MCPcopy Create free account
hub / github.com/firebase/quickstart-js / toggleSignIn

Function toggleSignIn

auth/email-link.ts:36–78  ·  view source on GitHub ↗

* Handles the sign in button press.

()

Source from the content-addressed store, hash-verified

34 * Handles the sign in button press.
35 */
36function toggleSignIn() {
37 // Disable the sign-in button during async sign-in tasks.
38 signInButton.disabled = true;
39
40 if (auth.currentUser) {
41 signOut(auth).catch(function (error) {
42 // Handle Errors here.
43 const errorCode = error.code;
44 const errorMessage = error.message;
45 handleError(error);
46 });
47 } else {
48 const email = emailInput.value;
49 // Sending email with sign-in link.
50 const actionCodeSettings = {
51 // URL you want to redirect back to. The domain (www.example.com) for this URL
52 // must be whitelisted in the Firebase Console.
53 url: window.location.href, // Here we redirect back to this same page.
54 handleCodeInApp: true, // This must be true.
55 };
56
57 sendSignInLinkToEmail(auth, email, actionCodeSettings)
58 .then(function () {
59 // Save the email locally so you don’t need to ask the user for it again if they open
60 // the link on the same device.
61 window.localStorage.setItem('emailForSignIn', email);
62 // The link was successfully sent. Inform the user.
63 alert(
64 'An email was sent to ' +
65 email +
66 '. Please use the link in the email to sign-in.',
67 );
68 // Re-enable the sign-in button.
69 signInButton.disabled = false;
70 })
71 .catch(function (error) {
72 // Handle Errors here.
73 const errorCode = error.code;
74 const errorMessage = error.message;
75 handleError(error);
76 });
77 }
78}
79
80/**
81 * Handles Errors from various Promises..

Callers

nothing calls this directly

Calls 1

handleErrorFunction · 0.85

Tested by

no test coverage detected