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 {replace} = useRouter()
|
||||||
const ready = !initializing
|
const ready = !initializing
|
||||||
|
|
||||||
const onAuthStateChanged = async (user: FirebaseAuthTypes.User | null) => {
|
const onAuthStateChangedHandler = async (authUser: FirebaseAuthTypes.User | null) => {
|
||||||
setUser(user);
|
setUser(authUser);
|
||||||
|
|
||||||
if (user) {
|
if (authUser) {
|
||||||
await refreshProfileData();
|
await refreshProfileData(authUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initializing) setInitializing(false);
|
if (initializing) setInitializing(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const refreshProfileData = async () => {
|
const refreshProfileData = async (authUser: FirebaseAuthTypes.User) => {
|
||||||
if (user) {
|
if (authUser) {
|
||||||
try {
|
try {
|
||||||
const documentSnapshot = await firestore()
|
const documentSnapshot = await firestore()
|
||||||
.collection("Profiles")
|
.collection("Profiles")
|
||||||
.doc(user.uid)
|
.doc(authUser.uid)
|
||||||
.get();
|
.get();
|
||||||
if (documentSnapshot.exists) {
|
if (documentSnapshot.exists) {
|
||||||
setProfileType(documentSnapshot.data()?.userType);
|
setProfileType(documentSnapshot.data()?.userType);
|
||||||
setProfileData(documentSnapshot.data() as UserProfile);
|
setProfileData(documentSnapshot.data() as UserProfile);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching user profile data:", error);
|
|
||||||
setProfileType(undefined);
|
setProfileType(undefined);
|
||||||
setProfileData(undefined);
|
setProfileData(undefined);
|
||||||
}
|
}
|
||||||
@ -60,7 +59,7 @@ export const AuthContextProvider: FC<{ children: ReactNode }> = ({children}) =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
|
const subscriber = auth().onAuthStateChanged(onAuthStateChangedHandler);
|
||||||
return subscriber;
|
return subscriber;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user