/
auth_handle_mgmt_query_params.js
49 lines (44 loc) · 1.73 KB
/
auth_handle_mgmt_query_params.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
// This snippet file was generated by processing the source file:
// ./auth-next/custom-email-handler.js
//
// To make edits to the snippets in this file, please edit the source
// [START auth_handle_mgmt_query_params_modular]
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
document.addEventListener('DOMContentLoaded', () => {
// TODO: Implement getParameterByName()
// Get the action to complete.
const mode = getParameterByName('mode');
// Get the one-time code from the query parameter.
const actionCode = getParameterByName('oobCode');
// (Optional) Get the continue URL from the query parameter if available.
const continueUrl = getParameterByName('continueUrl');
// (Optional) Get the language code if available.
const lang = getParameterByName('lang') || 'en';
// Configure the Firebase SDK.
// This is the minimum configuration required for the API to be used.
const config = {
'apiKey': "YOU_API_KEY" // Copy this key from the web initialization
// snippet found in the Firebase console.
};
const app = initializeApp(config);
const auth = getAuth(app);
// Handle the user management action.
switch (mode) {
case 'resetPassword':
// Display reset password handler and UI.
handleResetPassword(auth, actionCode, continueUrl, lang);
break;
case 'recoverEmail':
// Display email recovery handler and UI.
handleRecoverEmail(auth, actionCode, lang);
break;
case 'verifyEmail':
// Display email verification handler and UI.
handleVerifyEmail(auth, actionCode, continueUrl, lang);
break;
default:
// Error: invalid mode.
}
}, false);
// [END auth_handle_mgmt_query_params_modular]