* Handles automatically signing-in the app if we clicked on the sign-in link in the email.
()
| 92 | * Handles automatically signing-in the app if we clicked on the sign-in link in the email. |
| 93 | */ |
| 94 | function handleSignIn() { |
| 95 | if (isSignInWithEmailLink(auth, window.location.href)) { |
| 96 | // Disable the sign-in button during async sign-in tasks. |
| 97 | signInButton.disabled = true; |
| 98 | |
| 99 | // You can also get the other parameters passed in the query string such as state=STATE. |
| 100 | // Get the email if available. |
| 101 | let email = window.localStorage.getItem('emailForSignIn'); |
| 102 | if (!email) { |
| 103 | // User opened the link on a different device. To prevent session fixation attacks, ask the |
| 104 | // user to provide the associated email again. For example: |
| 105 | email = window.prompt( |
| 106 | "Please provide the email you'd like to sign-in with for confirmation.", |
| 107 | ); |
| 108 | } |
| 109 | if (email) { |
| 110 | // The client SDK will parse the code from the link for you. |
| 111 | signInWithEmailLink(auth, email, window.location.href) |
| 112 | .then(function (result) { |
| 113 | // Clear the URL to remove the sign-in link parameters. |
| 114 | window.history.replaceState( |
| 115 | {}, |
| 116 | document.title, |
| 117 | window.location.href.split('?')[0], |
| 118 | ); |
| 119 | // Clear email from storage. |
| 120 | window.localStorage.removeItem('emailForSignIn'); |
| 121 | // Signed-in user's information. |
| 122 | const user = result.user; |
| 123 | const additionalUserInfo = getAdditionalUserInfo(result); |
| 124 | const isNewUser = additionalUserInfo?.isNewUser; |
| 125 | console.log(result); |
| 126 | }) |
| 127 | .catch(function (error) { |
| 128 | // Handle Errors here. |
| 129 | const errorCode = error.code; |
| 130 | const errorMessage = error.message; |
| 131 | handleError(error); |
| 132 | }); |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | // Restore the previously used value of the email. |
| 138 | const email = window.localStorage.getItem('emailForSignIn'); |
no test coverage detected