-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathemail.js
78 lines (67 loc) · 1.95 KB
/
email.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
// [SNIPPET_REGISTRY disabled]
// [SNIPPETS_SEPARATION enabled]
function signInWithEmailPassword() {
const email = "[email protected]";
const password = "hunter2";
// [START auth_signin_password]
const { getAuth, signInWithEmailAndPassword } = require("firebase/auth");
const auth = getAuth();
signInWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
// ...
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
});
// [END auth_signin_password]
}
function signUpWithEmailPassword() {
const email = "[email protected]";
const password = "hunter2";
// [START auth_signup_password]
const { getAuth, createUserWithEmailAndPassword } = require("firebase/auth");
const auth = getAuth();
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed up
const user = userCredential.user;
// ...
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
// ..
});
// [END auth_signup_password]
}
function sendEmailVerification() {
// [START auth_send_email_verification]
const { getAuth, sendEmailVerification } = require("firebase/auth");
const auth = getAuth();
sendEmailVerification(auth.currentUser)
.then(() => {
// Email verification sent!
// ...
});
// [END auth_send_email_verification]
}
function sendPasswordReset() {
const email = "[email protected]";
// [START auth_send_password_reset]
const { getAuth, sendPasswordResetEmail } = require("firebase/auth");
const auth = getAuth();
sendPasswordResetEmail(auth, email)
.then(() => {
// Password reset email sent!
// ..
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
// ..
});
// [END auth_send_password_reset]
}