Reputation:
I use the library angular/angularfire2
and want to manage with it my authentication process. I want to create a user only if the email varification process succeeded. For now how I implemented it, it seems like the user already was created in my db before verification:
So far my Service looks as follows:
import { Injectable } from '@angular/core';
import {AngularFireAuth} from 'angularfire2/auth';
import {RegisterDataModel} from '../../components/register/register-data.model';
@Injectable({
providedIn: 'root'
})
export class RegistrationService {
constructor(private afAuth: AngularFireAuth) {
}
public register(register: RegisterDataModel): void {
this.afAuth.auth.createUserWithEmailAndPassword(register.email, register.password)
.then(() => {
const user = this.afAuth.auth.currentUser;
user.sendEmailVerification().then(() => console.log('please verify your email'))
.catch((err) => console.log(err));
}).catch(
(err) => console.log(err));
Does anyone know how to verify the user before creating/activating his acc?
Upvotes: 1
Views: 619
Reputation: 5272
You can't. You have to create the account before you can verify the account's email address, it's how Firebase is written on the backend.
If you're wanting to limit access to your app until the email is verified, you can easily write database rules to prevent access - see this thread here.
EDIT - As a significantly more complicated alternative, you could accomplish the same experience by creating your own verification email (with your own custom verification-link) using a Cloud Function, and then use another cloud function to create the user account after that verification-link has been clicked.
Upvotes: 2