Search Lessons, Code Snippets, and Videos
search by algolia
X
#native_cta# #native_desc# Sponsored by #native_company#

Handle Forgot Password in Angular With Firebase

written by Jeff Delaney
full courses and content on fireship.io

This quick code recipe using the Firebase API directly to request a new password. It will take your user to a firebase hosted webpage where they can update their password. You can change the details of the email template from the firebase console.

Gist

import { Injectable } from '@angular/core';
import * as firebase from 'firebase';
//...omitted
@Injectable()
export class AuthService {
resetPassword(email: string) {
var auth = firebase.auth();
return auth.sendPasswordResetEmail(email)
.then(() => console.log("email sent"))
.catch((error) => console.log(error))
}
}
view raw auth.service.ts hosted with ❤ by GitHub
<button (click)="resetPassword('hello@angularfirebase.com')">Reset Password</button>
import { Component } from '@angular/core';
import { AuthService } from "./somewhere/auth.service";
@Component({
// omitted...
})
export class ResetPasswordComponent {
resetPassword(email: string) {
this.auth.resetPassword(email)
}
}