Auth logic rework

This commit is contained in:
Milan Paunovic
2024-08-21 20:25:15 +02:00
parent 7500b7bdcb
commit 6b42476ef0
6 changed files with 254 additions and 200 deletions

View File

@ -5,7 +5,7 @@ import {useRouter} from "expo-router";
import firestore from "@react-native-firebase/firestore";
import {UserProfile} from "@/hooks/firebase/types/profileTypes";
type ProfileType = "parent" | "child" | "caregiver" | null;
export enum ProfileType { "parent", "child", "caregiver" }
interface IAuthContext {
user: FirebaseAuthTypes.User | null,
@ -28,6 +28,8 @@ export const AuthContextProvider: FC<{ children: ReactNode }> = ({children}) =>
const onAuthStateChanged = async (user: FirebaseAuthTypes.User | null) => {
setUser(user);
console.log(user)
if (user) {
try {
const documentSnapshot = await firestore()
@ -41,7 +43,7 @@ export const AuthContextProvider: FC<{ children: ReactNode }> = ({children}) =>
} catch (error) {
console.error("Error fetching user profile type:", error);
setProfileType(null);
setProfileType(undefined);
}
}