Преглед на файлове

client/web: refresh auth after syno login

Makes sure we refresh auth state after synology auth has run.

Updates #10261

Signed-off-by: Sonia Appasamy <[email protected]>
Sonia Appasamy преди 2 години
родител
ревизия
343f4e4f26
променени са 1 файла, в които са добавени 6 реда и са изтрити 0 реда
  1. 6 0
      client/web/src/hooks/auth.ts

+ 6 - 0
client/web/src/hooks/auth.ts

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