mirror of
https://github.com/urosran/cally.git
synced 2025-07-15 01:35:22 +00:00
21 lines
813 B
TypeScript
21 lines
813 B
TypeScript
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.")
|
|
}
|
|
},
|
|
});
|
|
} |