Created
April 9, 2020 15:10
-
-
Save himanshusaraswat/9e02752bb0ff68f700f7806148b8031b to your computer and use it in GitHub Desktop.
Lays down the steps to send an email link for sign-in (passwordless sign-in). Removes the hassle of remembering passwords for your end-users & for you as developers to implement "forgot password" or "verify-email" workflows.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async sendEmail(email: string) { | |
const actionCodeSettings = { | |
// URL you want to redirect back to. The domain (www.example.com) for this | |
// URL must be whitelisted in the Firebase Console. | |
url: environment.redirectURL, | |
// This must be true. | |
handleCodeInApp: true | |
}; | |
try { | |
await this.afAuth.auth.sendSignInLinkToEmail( | |
email, | |
actionCodeSettings | |
); | |
// The link was successfully sent. Inform the user. | |
// Save the email locally so you don't need to ask the user for it again | |
// if they open the link on the same device. | |
window.localStorage.setItem('emailForSignIn', email); | |
// Material snackbar for informing user:https://material.angular.io/components/snack-bar/overview | |
this.snackBarService.openSnackBar(sendEmail.welcome, 'welcome'); | |
} catch (error) { | |
// Some error occurred, you can inspect the code: error.code | |
this.handleError(error); | |
} finally { | |
// I have a loader in place switch it off | |
this.setLoadingState(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment