mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 16:34:54 +00:00
Editing calendar events
- Fixed an issue with the profile data not being read from db becaue of the local state not being updated instantly
This commit is contained in:
@ -30,29 +30,28 @@ export const AuthContextProvider: FC<{ children: ReactNode }> = ({children}) =>
|
||||
const {replace} = useRouter()
|
||||
const ready = !initializing
|
||||
|
||||
const onAuthStateChanged = async (user: FirebaseAuthTypes.User | null) => {
|
||||
setUser(user);
|
||||
const onAuthStateChangedHandler = async (authUser: FirebaseAuthTypes.User | null) => {
|
||||
setUser(authUser);
|
||||
|
||||
if (user) {
|
||||
await refreshProfileData();
|
||||
if (authUser) {
|
||||
await refreshProfileData(authUser);
|
||||
}
|
||||
|
||||
if (initializing) setInitializing(false);
|
||||
}
|
||||
|
||||
const refreshProfileData = async () => {
|
||||
if (user) {
|
||||
const refreshProfileData = async (authUser: FirebaseAuthTypes.User) => {
|
||||
if (authUser) {
|
||||
try {
|
||||
const documentSnapshot = await firestore()
|
||||
.collection("Profiles")
|
||||
.doc(user.uid)
|
||||
.doc(authUser.uid)
|
||||
.get();
|
||||
if (documentSnapshot.exists) {
|
||||
setProfileType(documentSnapshot.data()?.userType);
|
||||
setProfileData(documentSnapshot.data() as UserProfile);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching user profile data:", error);
|
||||
setProfileType(undefined);
|
||||
setProfileData(undefined);
|
||||
}
|
||||
@ -60,7 +59,7 @@ export const AuthContextProvider: FC<{ children: ReactNode }> = ({children}) =>
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
|
||||
const subscriber = auth().onAuthStateChanged(onAuthStateChangedHandler);
|
||||
return subscriber;
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user