-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApiService.js
86 lines (77 loc) · 2.03 KB
/
ApiService.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { initializeApp } from 'firebase/app';
import {
getAuth,
signInWithEmailAndPassword,
createUserWithEmailAndPassword
} from 'firebase/auth';
import { getFirestore, doc, setDoc, updateDoc } from 'firebase/firestore';
import { initializeAuth, getReactNativePersistence } from 'firebase/auth';
import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';
// Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyCe-_ENL-QmW__8BrE4beO4BLuKV7XPYUM",
authDomain: "schedulerx-3bf1a.firebaseapp.com",
projectId: "schedulerx-3bf1a",
storageBucket: "schedulerx-3bf1a.appspot.com",
messagingSenderId: "1088673802858",
appId: "1:1088673802858:android:2cc8a514d360b74b103813"
};
// Initialize Firebase App
const app = initializeApp(firebaseConfig);
// Get auth instance
const auth = initializeAuth(app, {
persistence: getReactNativePersistence(ReactNativeAsyncStorage)
});
// Get Firestore instance
const db = getFirestore(app);
export const loginUser = async (email, password) => {
try {
const userCredential = await signInWithEmailAndPassword(auth, email, password);
return userCredential.user;
} catch (error) {
console.error(error);
throw error;
}
};
export const registerUser = async (
email,
password,
name,
phone_number,
date_of_birth
) => {
try {
const userCredential = await createUserWithEmailAndPassword(auth, email, password);
const user = userCredential.user;
await setDoc(doc(db, 'users', user.uid), {
name,
phone_number,
date_of_birth
});
return user;
} catch (error) {
console.error("Something wrong", error);
throw error;
}
};
export const updateBiometrics = async (
userId,
height,
weight,
fitnessLevel,
fitnessGoal
) => {
try {
const userDocRef = doc(db, 'users', userId);
await updateDoc(userDocRef, {
height,
weight,
fitnessLevel,
fitnessGoal
});
return { status: 'success' };
} catch (error) {
console.error("Something wrong", error);
throw error;
}
};