Loading mobile/src/auth/contexts/auth_context.tsx +8 −19 Original line number Diff line number Diff line Loading @@ -35,15 +35,15 @@ export const AuthContextProvider = ({ children }: AuthContextProviderProps) => { const checkSession = async () => { try { const user = await SecureStore.getItemAsync("user"); const token = await SecureStore.getItemAsync("token"); const user = SecureStore.getItem("user"); const token = SecureStore.getItem("token"); console.log(user); console.log(token); if (user && token) { const recoveredUser = JSON.parse(user) as UserInfoEntity; setUser(recoveredUser); const ssKey = recoveredUser.email.split("@")[0]; const userPreferences = await SecureStore.getItemAsync(ssKey); const userPreferences = SecureStore.getItem(ssKey); if (userPreferences) { const parsedUserPreferences = JSON.parse( userPreferences Loading @@ -54,10 +54,7 @@ export const AuthContextProvider = ({ children }: AuthContextProviderProps) => { isFirstTime: true, isVerifiedEmail: false, }; await SecureStore.setItemAsync( ssKey, JSON.stringify(emptyUserPreferences) ); SecureStore.setItem(ssKey, JSON.stringify(emptyUserPreferences)); setIsVerified(false); } axios.defaults.headers.common["Authorization"] = `Bearer ${token}`; Loading @@ -73,12 +70,12 @@ export const AuthContextProvider = ({ children }: AuthContextProviderProps) => { const verify = async () => { if (!user) return; const sskey = user.email.split("@")[0]; const userPreferences = await SecureStore.getItemAsync(sskey); const userPreferences = SecureStore.getItem(sskey); if (!userPreferences) return; const parsedUserPreferences = JSON.parse( userPreferences ) as UserPreferences; await SecureStore.setItemAsync( SecureStore.setItem( sskey, JSON.stringify({ ...parsedUserPreferences, isVerifiedEmail: true }) ); Loading @@ -90,8 +87,8 @@ export const AuthContextProvider = ({ children }: AuthContextProviderProps) => { }; const login = async (userInfo: UserInfoEntity, token: string) => { await SecureStore.setItemAsync("user", JSON.stringify(userInfo)); await SecureStore.setItemAsync("token", token); SecureStore.setItem("user", JSON.stringify(userInfo)); SecureStore.setItem("token", token); await saveUser(userInfo); axios.defaults.headers.common["Authorization"] = `Bearer ${token}`; await verify(); Loading @@ -106,14 +103,6 @@ export const AuthContextProvider = ({ children }: AuthContextProviderProps) => { useEffect(() => { checkSession(); const timeout = setTimeout(() => { if (isLoading) { setIsLoading(false); } }, 3000); return () => clearTimeout(timeout); }, []); return ( Loading mobile/src/common/contexts/set_up_context.tsx +4 −10 Original line number Diff line number Diff line Loading @@ -36,16 +36,13 @@ export const SetUpContextProvider = ({ return; } const sskey = user.email.split("@")[0]; const userPreferences = await SecureStore.getItemAsync(sskey); const userPreferences = SecureStore.getItem(sskey); if (userPreferences) { const parsedUserPreferences = JSON.parse( userPreferences ) as UserPreferences; parsedUserPreferences.isFirstTime = false; await SecureStore.setItemAsync( sskey, JSON.stringify(parsedUserPreferences) ); SecureStore.setItem(sskey, JSON.stringify(parsedUserPreferences)); setIsFirstTime(false); } setIsLoading(false); Loading @@ -66,7 +63,7 @@ export const SetUpContextProvider = ({ return; } const sskey = user.email.split("@")[0]; const value = await SecureStore.getItemAsync(sskey); const value = SecureStore.getItem(sskey); if (value) { const userPreferences = JSON.parse(value) as UserPreferences; setIsFirstTime(userPreferences.isFirstTime); Loading @@ -75,10 +72,7 @@ export const SetUpContextProvider = ({ isFirstTime: true, isVerifiedEmail: false, }; await SecureStore.setItemAsync( sskey, JSON.stringify(emptyUserPreferences) ); SecureStore.setItem(sskey, JSON.stringify(emptyUserPreferences)); } } catch { console.log("Error checking session"); Loading Loading
mobile/src/auth/contexts/auth_context.tsx +8 −19 Original line number Diff line number Diff line Loading @@ -35,15 +35,15 @@ export const AuthContextProvider = ({ children }: AuthContextProviderProps) => { const checkSession = async () => { try { const user = await SecureStore.getItemAsync("user"); const token = await SecureStore.getItemAsync("token"); const user = SecureStore.getItem("user"); const token = SecureStore.getItem("token"); console.log(user); console.log(token); if (user && token) { const recoveredUser = JSON.parse(user) as UserInfoEntity; setUser(recoveredUser); const ssKey = recoveredUser.email.split("@")[0]; const userPreferences = await SecureStore.getItemAsync(ssKey); const userPreferences = SecureStore.getItem(ssKey); if (userPreferences) { const parsedUserPreferences = JSON.parse( userPreferences Loading @@ -54,10 +54,7 @@ export const AuthContextProvider = ({ children }: AuthContextProviderProps) => { isFirstTime: true, isVerifiedEmail: false, }; await SecureStore.setItemAsync( ssKey, JSON.stringify(emptyUserPreferences) ); SecureStore.setItem(ssKey, JSON.stringify(emptyUserPreferences)); setIsVerified(false); } axios.defaults.headers.common["Authorization"] = `Bearer ${token}`; Loading @@ -73,12 +70,12 @@ export const AuthContextProvider = ({ children }: AuthContextProviderProps) => { const verify = async () => { if (!user) return; const sskey = user.email.split("@")[0]; const userPreferences = await SecureStore.getItemAsync(sskey); const userPreferences = SecureStore.getItem(sskey); if (!userPreferences) return; const parsedUserPreferences = JSON.parse( userPreferences ) as UserPreferences; await SecureStore.setItemAsync( SecureStore.setItem( sskey, JSON.stringify({ ...parsedUserPreferences, isVerifiedEmail: true }) ); Loading @@ -90,8 +87,8 @@ export const AuthContextProvider = ({ children }: AuthContextProviderProps) => { }; const login = async (userInfo: UserInfoEntity, token: string) => { await SecureStore.setItemAsync("user", JSON.stringify(userInfo)); await SecureStore.setItemAsync("token", token); SecureStore.setItem("user", JSON.stringify(userInfo)); SecureStore.setItem("token", token); await saveUser(userInfo); axios.defaults.headers.common["Authorization"] = `Bearer ${token}`; await verify(); Loading @@ -106,14 +103,6 @@ export const AuthContextProvider = ({ children }: AuthContextProviderProps) => { useEffect(() => { checkSession(); const timeout = setTimeout(() => { if (isLoading) { setIsLoading(false); } }, 3000); return () => clearTimeout(timeout); }, []); return ( Loading
mobile/src/common/contexts/set_up_context.tsx +4 −10 Original line number Diff line number Diff line Loading @@ -36,16 +36,13 @@ export const SetUpContextProvider = ({ return; } const sskey = user.email.split("@")[0]; const userPreferences = await SecureStore.getItemAsync(sskey); const userPreferences = SecureStore.getItem(sskey); if (userPreferences) { const parsedUserPreferences = JSON.parse( userPreferences ) as UserPreferences; parsedUserPreferences.isFirstTime = false; await SecureStore.setItemAsync( sskey, JSON.stringify(parsedUserPreferences) ); SecureStore.setItem(sskey, JSON.stringify(parsedUserPreferences)); setIsFirstTime(false); } setIsLoading(false); Loading @@ -66,7 +63,7 @@ export const SetUpContextProvider = ({ return; } const sskey = user.email.split("@")[0]; const value = await SecureStore.getItemAsync(sskey); const value = SecureStore.getItem(sskey); if (value) { const userPreferences = JSON.parse(value) as UserPreferences; setIsFirstTime(userPreferences.isFirstTime); Loading @@ -75,10 +72,7 @@ export const SetUpContextProvider = ({ isFirstTime: true, isVerifiedEmail: false, }; await SecureStore.setItemAsync( sskey, JSON.stringify(emptyUserPreferences) ); SecureStore.setItem(sskey, JSON.stringify(emptyUserPreferences)); } } catch { console.log("Error checking session"); Loading