Merge branch 'dp/calendar-sync' into dev

# Conflicts:
#	components/pages/settings/CalendarSettingsPage.tsx
#	yarn.lock
This commit is contained in:
Milan Paunovic
2024-10-06 00:07:24 +02:00
18 changed files with 987 additions and 740 deletions

View File

@ -14,8 +14,9 @@ export enum ProfileType {
interface IAuthContext {
user: FirebaseAuthTypes.User | null,
profileType?: ProfileType,
profileData?: UserProfile
setProfileData: (profileData: UserProfile) => void
profileData?: UserProfile,
setProfileData: (profileData: UserProfile) => void,
refreshProfileData: () => Promise<void>
}
const AuthContext = createContext<IAuthContext>(undefined!)
@ -32,8 +33,14 @@ export const AuthContextProvider: FC<{ children: ReactNode }> = ({children}) =>
const onAuthStateChanged = async (user: FirebaseAuthTypes.User | null) => {
setUser(user);
console.log(user)
if (user) {
await refreshProfileData();
}
if (initializing) setInitializing(false);
}
const refreshProfileData = async () => {
if (user) {
try {
const documentSnapshot = await firestore()
@ -42,17 +49,15 @@ export const AuthContextProvider: FC<{ children: ReactNode }> = ({children}) =>
.get();
if (documentSnapshot.exists) {
setProfileType(documentSnapshot.data()?.userType);
setProfileData(documentSnapshot.data() as UserProfile)
setProfileData(documentSnapshot.data() as UserProfile);
}
} catch (error) {
console.error("Error fetching user profile type:", error);
console.error("Error fetching user profile data:", error);
setProfileType(undefined);
setProfileData(undefined);
}
}
if (initializing) setInitializing(false);
}
};
useEffect(() => {
const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
@ -78,10 +83,10 @@ export const AuthContextProvider: FC<{ children: ReactNode }> = ({children}) =>
}
return (
<AuthContext.Provider value={{user, profileType, profileData, setProfileData}}>
<AuthContext.Provider value={{user, profileType, profileData, setProfileData, refreshProfileData}}>
{children}
</AuthContext.Provider>
)
}
export const useAuthContext = () => useContext(AuthContext)!;
export const useAuthContext = () => useContext(AuthContext)!;