-
Notifications
You must be signed in to change notification settings - Fork 241
/
auth_handle_reset_password.js
42 lines (35 loc) · 1.62 KB
/
auth_handle_reset_password.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
// This snippet file was generated by processing the source file:
// ./auth-next/custom-email-handler.js
//
// To update the snippets in this file, edit the source and then run
// 'npm run snippets'.
// [START auth_handle_reset_password_modular]
import { verifyPasswordResetCode, confirmPasswordReset } from "firebase/auth";
function handleResetPassword(auth, actionCode, continueUrl, lang) {
// Localize the UI to the selected language as determined by the lang
// parameter.
// Verify the password reset code is valid.
verifyPasswordResetCode(auth, actionCode).then((email) => {
const accountEmail = email;
// TODO: Show the reset screen with the user's email and ask the user for
// the new password.
const newPassword = "...";
// Save the new password.
confirmPasswordReset(auth, actionCode, newPassword).then((resp) => {
// Password reset has been confirmed and new password updated.
// TODO: Display a link back to the app, or sign-in the user directly
// if the page belongs to the same domain as the app:
// auth.signInWithEmailAndPassword(accountEmail, newPassword);
// TODO: If a continue URL is available, display a button which on
// click redirects the user back to the app via continueUrl with
// additional state determined from that URL's parameters.
}).catch((error) => {
// Error occurred during confirmation. The code might have expired or the
// password is too weak.
});
}).catch((error) => {
// Invalid or expired action code. Ask user to try to reset the password
// again.
});
}
// [END auth_handle_reset_password_modular]