mirror of
https://github.com/urosran/cally.git
synced 2026-10-23 09:47:53 +00:00
LOgging in with qr code added
This commit is contained in:
@@ -16,6 +16,7 @@ export interface User {
|
||||
email: string
|
||||
password: string
|
||||
familyId?: string
|
||||
uid?: string
|
||||
}
|
||||
|
||||
export interface ParentProfile extends UserProfile {
|
||||
|
||||
@@ -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"]})
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -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.")
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user