-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebase.js
71 lines (64 loc) · 1.61 KB
/
firebase.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
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
import {
getAuth,
signInWithPopup,
signOut,
GoogleAuthProvider,
createUserWithEmailAndPassword,
signInWithEmailAndPassword,
} from "firebase/auth";
const firebaseConfig = {
apiKey: "AIzaSyA9BoQ11tKO0WJjaqrtIuf21S54T7oYP2U",
authDomain: "assignments-finder.firebaseapp.com",
projectId: "assignments-finder",
storageBucket: "assignments-finder.appspot.com",
messagingSenderId: "1022708235273",
appId: "1:1022708235273:web:1f923e106d74ca5d628cd8",
measurementId: "G-1Y6H7V496Q",
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const googleProvider = new GoogleAuthProvider();
const auth = getAuth(app);
const registerWithEmailAndPassword = async (email, password) => {
try {
return await createUserWithEmailAndPassword(auth, email, password);
} catch (err) {
console.log(err);
alert(err.message);
}
};
const loginWithEmailAndPassword = async (email, password) => {
try {
return await signInWithEmailAndPassword(auth, email, password);
} catch (err) {
console.log(err);
}
};
const signInWithGoogle = async () => {
try {
const res = await signInWithPopup(auth, googleProvider);
console.log(res.user);
return res;
} catch (err) {
console.log(err);
}
};
const logout = async () => {
try {
await signOut(auth);
} catch (err) {
console.log(err);
}
};
export {
app,
signInWithGoogle,
logout,
auth,
registerWithEmailAndPassword,
loginWithEmailAndPassword,
};
// export const auth = getAuth();
// const analytics = getAnalytics(app);