mirror of
https://github.com/urosran/cally.git
synced 2026-10-24 19:57:54 +00:00
Auth logic rework
This commit is contained in:
@@ -1,12 +1,23 @@
|
||||
import {useMutation} from "react-query";
|
||||
import {useMutation, useQueryClient} from "react-query";
|
||||
import {UserProfile} from "@/hooks/firebase/types/profileTypes";
|
||||
import functions from '@react-native-firebase/functions';
|
||||
import {ProfileType, useAuthContext} from "@/contexts/AuthContext";
|
||||
|
||||
export const useCreateSubUser = () => {
|
||||
const queryClient = useQueryClient()
|
||||
const { profileType } = useAuthContext()
|
||||
|
||||
return useMutation({
|
||||
mutationKey: ["createSubUser"],
|
||||
mutationFn: async ({email, password, ...userProfile}: { email: string, password: string } & UserProfile) => {
|
||||
return await functions().httpsCallable("createSubUser")({email, password, ...userProfile})
|
||||
if(profileType === ProfileType.parent) {
|
||||
return await functions().httpsCallable("createSubUser")({email, password, ...userProfile})
|
||||
} else {
|
||||
throw Error("Can't create sub-users as a non-parent.")
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({queryKey: ["getChildrenByParentId"]})
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user