I'm currently working on setting up an email verification system using Angular and the Google Firebase API. I came across the sendEmailVerification()
function through this reference, but I'm a bit unsure about how to correctly implement it. To address this, I decided to create a new function within my service.ts
file, but I'm not entirely confident in its accuracy. Could someone offer some guidance on this matter?
//auth.service.ts
private authState: any = null;
get currentUserId(): string {
return (this.authState !== null) ? this.authState.uid : ''
}
signUpWithEmail(email: string, password: string) {
return this.afAuth.auth.createUserWithEmailAndPassword(email, password)
.then((user) => {
this.authState;
})
.catch(error => {
console.log(error)
throw error
});
}
emailVerfication() {
this.authState.auth.getAuth().auth.sendEmailVerification();
}
//app.component.ts
onSignUp(): void {
//this.clearErrorMessage()
if (this.validateForm(this.email, this.password)) {
this.AuthService.signUpWithEmail(this.email, this.password).catch(error => {
this.error = error
});
//this.AuthService.emailVerfication();
} else {
this.AuthService.emailVerfication();
}
}
<form (ngSubmit)="onSignUp()">
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" name="email" required [(ngModel)]="email">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" required [(ngModel)]="password">
</div>
<button type="submit" class="btn btn-success">Register</button>
</form>
Although no errors were displayed, it seems that the verification email was not successfully sent to my email account. If additional code snippets or information are required to assist with troubleshooting, please let me know.