LOgging in with qr code added

This commit is contained in:
Milan Paunovic
2024-09-29 23:03:21 +02:00
parent 92f335543f
commit 5922179584
15 changed files with 820 additions and 993 deletions
+1
View File
@@ -16,6 +16,7 @@ export interface User {
email: string
password: string
familyId?: string
uid?: string
}
export interface ParentProfile extends UserProfile {
+3 -1
View File
@@ -12,8 +12,9 @@ export const useCreateSubUser = () => {
mutationFn: async ({email, ...userProfile}: { email: string } & UserProfile) => {
if (profileType === ProfileType.PARENT) {
return await functions().httpsCallable("createSubUser")({
...userProfile,
email,
userProfile: {...userProfile, familyId: profileData?.familyId}
familyId: profileData?.familyId
})
} else {
throw Error("Can't create sub-users as a non-parent.")
@@ -21,6 +22,7 @@ export const useCreateSubUser = () => {
},
onSuccess: () => {
queryClient.invalidateQueries({queryKey: ["getChildrenByParentId"]})
queryClient.invalidateQueries({queryKey: ["familyMembers"]})
}
});
}
+21
View File
@@ -0,0 +1,21 @@
import {useMutation} from "react-query";
import functions, {FirebaseFunctionsTypes} from '@react-native-firebase/functions';
import auth from "@react-native-firebase/auth";
export const useLoginWithQrCode = () => {
return useMutation({
mutationKey: ["loginWithQrCode"],
mutationFn: async ({userId}: { userId: string }) => {
try {
const res = await functions().httpsCallable("generateCustomToken")({userId}) as FirebaseFunctionsTypes.HttpsCallableResult<{
token: string
}>
console.log(res)
await auth().signInWithCustomToken(res?.data?.token)
} catch (e) {
console.error(e)
throw Error("Failed to login with QR code.")
}
},
});
}