-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth-util.js
38 lines (37 loc) · 1010 Bytes
/
auth-util.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
import { auth } from "@/firebase";
import {
signInWithEmailAndPassword,
signInWithPopup,
GoogleAuthProvider,
createUserWithEmailAndPassword,
signOut,
} from "firebase/auth";
const provider = new GoogleAuthProvider();
export async function loginWithEmail(email, password) {
try {
await signInWithEmailAndPassword(auth, email, password);
} catch (error) {
alert(`Unsuccessful Login: ${error.message}`);
}
}
export async function loginWithGoogle() {
signInWithPopup(auth, provider)
.then((result) => {
const user = result.user;
console.log(`Welcome ${user.displayName}`);
})
.catch((error) => {
alert(`Unsuccessful Login: ${error.message}`);
});
}
export async function signUpWithEmail(email, password) {
try {
await createUserWithEmailAndPassword(auth, email, password);
console.log("Successful Signup");
} catch (error) {
alert(`Unsuccessful Signup: ${error.message}`);
}
}
export async function logout() {
await signOut(auth);
}