I have a simple form to register and signin, using firebase to store and for authentication. Registered user can receive confirmation mail through firebase. But unverified users can also able to login, what am doing wrong here.?
login-page.component.ts
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators, AbstractControl } from '@angular/forms';
import * as firebase from 'firebase';
@Component({
selector: 'app-login-page',
templateUrl: './login-page.component.html',
styleUrls: ['./login-page.component.css']
})
export class LoginPageComponent implements OnInit {
signin:FormGroup;
constructor(private fb: FormBuilder) {
this.signin = fb.group({
email : [null, Validators.compose([Validators.required, this.nospaceValidator])],
password : [null, Validators.required]
});
}
ngOnInit() {
}
signUp(){
let values = this.signin.value;
console.log(values.email,values.password)
firebase.auth().createUserWithEmailAndPassword(values.email,values.password)
.then(
function(user){
if(user && user.emailVerified === false){
user.sendEmailVerification()
.then(function(){
console.log("email verification sent to user");
});
}
}
)
.catch(
function(error) {
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorMessage)
});
}
signIn(){
firebase.auth().onAuthStateChanged(
function(user) {
if (user.emailVerified) {
console.log('Email is verified');
}
else {
console.log('Email is not verified');
}
});
}
}