|
|
@ -25,6 +25,7 @@ export type AuthResponse = {
|
|
|
|
export default function useAuth() {
|
|
|
|
export default function useAuth() {
|
|
|
|
const [data, setData] = useState<AuthResponse>()
|
|
|
|
const [data, setData] = useState<AuthResponse>()
|
|
|
|
const [loading, setLoading] = useState<boolean>(true)
|
|
|
|
const [loading, setLoading] = useState<boolean>(true)
|
|
|
|
|
|
|
|
const [ranSynoAuth, setRanSynoAuth] = useState<boolean>(false)
|
|
|
|
|
|
|
|
|
|
|
|
const loadAuth = useCallback(() => {
|
|
|
|
const loadAuth = useCallback(() => {
|
|
|
|
setLoading(true)
|
|
|
|
setLoading(true)
|
|
|
@ -37,6 +38,7 @@ export default function useAuth() {
|
|
|
|
.then((r) => r.json())
|
|
|
|
.then((r) => r.json())
|
|
|
|
.then((a) => {
|
|
|
|
.then((a) => {
|
|
|
|
setSynoToken(a.SynoToken)
|
|
|
|
setSynoToken(a.SynoToken)
|
|
|
|
|
|
|
|
setRanSynoAuth(true)
|
|
|
|
setLoading(false)
|
|
|
|
setLoading(false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
break
|
|
|
|
break
|
|
|
@ -79,6 +81,10 @@ export default function useAuth() {
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [])
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
loadAuth() // Refresh auth state after syno auth runs
|
|
|
|
|
|
|
|
}, [loadAuth, ranSynoAuth])
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
data,
|
|
|
|
data,
|
|
|
|
loading,
|
|
|
|
loading,
|
|
|
|