Reputation: 20733
I'm using Firebase and Firestore auth in an angular application(with angular-fire), which works nicely.
For the feature "password forgotten" and "email validation", I do call those methods on the AngularFireAuth
service:
sendVerificationMail() {
return this.afAuth.currentUser
.then((u: any) => u.sendEmailVerification())
.then(() => {
this.router.navigate(['/', 'auth', 'verify-email']);
});
}
async forgotPassword(passwordResetEmail: string) {
try {
await this.afAuth.sendPasswordResetEmail(passwordResetEmail);
window.alert('Password reset email sent, check your inbox.');
} catch (error) {
window.alert(error);
}
}
It works, I receive email to validate my email or to reset my password, but:
https://xxxx.firebaseapp.com
instead of my custom domainMy question is, can I provide URL to some custom page? Or customize the design? Or some redirect action? To have something that is a bit better integrated to my website?
Upvotes: 2
Views: 3895
Reputation: 445
You can customize the Password Reset email under Firebase Console -> Auth -> Email Templates -> Password Reset, and change the link in the email to point to your own page. Note that the placeholder will be replaced by the password reset code in the URL.
Then, in your custom page, you can read the password reset code from the URL and do
firebase.auth().confirmPasswordReset(code, newPassword) .then(function() { // Success }) .catch(function() { // Invalid code })
https://firebase.google.com/docs/reference/js/firebase.auth.Auth#confirmPasswordReset https://firebase.google.com/docs/reference/js/firebase.auth.Auth#verifyPasswordResetCode
Upvotes: 4
Reputation: 445
This is for redirect after password reset, You have to pass a continue URL via ActionCodeSettings to redirect the user back to the app:
var actionCodeSettings = {
// After password reset, the user will be give the ability to go back
// to this page.
url: 'https://www.example.com/afterPasswordReset',
handleCodeInApp: false
};
firebase.auth().sendPasswordResetEmail(email, actionCodeSettings)
.then(function() {
// Password reset email sent.
})
.catch(function(error) {
// Error occurred. Inspect error.code.
});
Learn more about ActionCodeSettings and passing state in redirect: https://firebase.google.com/docs/auth/web/passing-state-in-email-actions
You can also build your own custom landing page here: https://firebase.google.com/docs/auth/custom-email-handler
Upvotes: 3