mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 15:17:17 +00:00
50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
import {useMutation} from "@tanstack/react-query";
|
|
import auth from "@react-native-firebase/auth";
|
|
import {ProfileType, useAuthContext} from "@/contexts/AuthContext";
|
|
import {useSetUserData} from "./useSetUserData";
|
|
import {uuidv4} from "@firebase/util";
|
|
import * as Localization from "expo-localization";
|
|
|
|
export const useSignUp = () => {
|
|
const {setRedirectOverride} = useAuthContext()
|
|
const {mutateAsync: setUserData} = useSetUserData();
|
|
|
|
return useMutation({
|
|
mutationKey: ["signUp"],
|
|
mutationFn: async ({
|
|
email,
|
|
password,
|
|
firstName,
|
|
lastName,
|
|
birthday
|
|
}: {
|
|
email: string;
|
|
password: string;
|
|
firstName: string;
|
|
lastName: string;
|
|
birthday: Date;
|
|
}) => {
|
|
setRedirectOverride(true)
|
|
|
|
await auth()
|
|
.createUserWithEmailAndPassword(email, password)
|
|
.then(async (res) => {
|
|
try {
|
|
await setUserData({
|
|
newUserData: {
|
|
userType: ProfileType.PARENT,
|
|
firstName: firstName,
|
|
lastName: lastName,
|
|
familyId: uuidv4(),
|
|
timeZone: Localization.getCalendars()[0].timeZone,
|
|
birthday: birthday
|
|
},
|
|
customUser: res.user,
|
|
});
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
});
|
|
},
|
|
});
|
|
}; |