mirror of
https://github.com/urosran/cally.git
synced 2025-07-09 22:57:16 +00:00
default Household name
This commit is contained in:
@ -70,9 +70,9 @@ if (Platform.OS === 'ios') {
|
||||
}
|
||||
|
||||
if (__DEV__) {
|
||||
// functions().useEmulator("localhost", 5001);
|
||||
// firestore().useEmulator("localhost", 5471);
|
||||
// auth().useEmulator("http://localhost:9099");
|
||||
functions().useEmulator("localhost", 5001);
|
||||
firestore().useEmulator("localhost", 5471);
|
||||
auth().useEmulator("http://localhost:9099");
|
||||
}
|
||||
|
||||
type TextStyleBase =
|
||||
|
@ -1,30 +1,49 @@
|
||||
import {useMutation} from "@tanstack/react-query";
|
||||
import auth from "@react-native-firebase/auth";
|
||||
import firestore from "@react-native-firebase/firestore";
|
||||
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 {setRedirectOverride} = useAuthContext();
|
||||
const {mutateAsync: setUserData} = useSetUserData();
|
||||
|
||||
const createHouseholdIfNeeded = async (familyId: string, lastName: string) => {
|
||||
try {
|
||||
const householdRef = firestore().collection("Households");
|
||||
const snapshot = await householdRef.where("familyId", "==", familyId).get();
|
||||
|
||||
if (snapshot.empty) {
|
||||
await householdRef.add({
|
||||
familyId,
|
||||
name: lastName
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error creating household:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
return useMutation({
|
||||
mutationKey: ["signUp"],
|
||||
mutationFn: async ({
|
||||
email,
|
||||
password,
|
||||
firstName,
|
||||
lastName,
|
||||
birthday
|
||||
}: {
|
||||
email,
|
||||
password,
|
||||
firstName,
|
||||
lastName,
|
||||
birthday
|
||||
}: {
|
||||
email: string;
|
||||
password: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
birthday: Date;
|
||||
}) => {
|
||||
setRedirectOverride(true)
|
||||
setRedirectOverride(true);
|
||||
const familyId = uuidv4();
|
||||
|
||||
await auth()
|
||||
.createUserWithEmailAndPassword(email, password)
|
||||
@ -35,12 +54,14 @@ export const useSignUp = () => {
|
||||
userType: ProfileType.PARENT,
|
||||
firstName: firstName,
|
||||
lastName: lastName,
|
||||
familyId: uuidv4(),
|
||||
familyId: familyId,
|
||||
timeZone: Localization.getCalendars()[0].timeZone,
|
||||
birthday: birthday
|
||||
},
|
||||
customUser: res.user,
|
||||
});
|
||||
|
||||
await createHouseholdIfNeeded(familyId, lastName);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
Reference in New Issue
Block a user