2017-12-27 29 views
0

나는 firebase를 사용하여 저장하고 인증하기 위해 등록하고 서명하는 간단한 양식을 가지고 있습니다. 등록 된 사용자는 firebase를 통해 확인 메일을받을 수 있습니다. 그러나 확인되지 않은 사용자도 로그인 할 수 있습니다. 여기서 잘못된 것은 무엇입니까?인증되지 않은 사용자도 로그인 할 수 있습니다.

로그인-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'); 
    } 
}); 
} 
} 
+0

사용자를 어디에서 만들지 만 실제로 로그인하는 위치는 어디입니까? – DoesData

답변

0

. Firebase 인증을 사용하면 사용자의 전자 메일 주소를 확인하는 메시지를 보낼 수 있지만 인증되지 않은 전자 메일 주소를 가진 사용자가 로그인하지 못하게 할 수는 없습니다.

특정 리소스를 확인 된 이메일 주소를 사용하면 해당 자원을 보호 할 수 있습니다. 데이터를 저장하기 위해 중포 기지 데이터베이스를 사용하는 경우, 예를 들어, 당신과 함께 확인 이메일 주소 만 사용자가 액세스 할 수있는 데이터를 만들 수있는이에 대한 자세한 내용은

{ 
    "rules": { 
    ".read": "auth.token.email_verified == true" 
    } 
} 

, 여기 내 대답을 참조하십시오 How do I lock down Firebase Database to any user from a specific (email) domain?

0

Franks 응답에 추가하면이 코드를 사용하여 이메일 확인을하지 않은 사용자가 앱에 로그인하지 못하도록 방지 할 수도 있습니다.

if (user.emailVerified) { 
    // sign the user into your app 
} 
else { 
    // alert the user that the cannot sign in until they verify their email 
    // You probably want to offer to send another email verification here too 
} 
+0

수정 한 내용. – codedamn

+0

아무것도 나는 당신의 이메일이 확인되지 않으면 사용자 로그인을 막기 위해 바로 확인하면 사용할 수 있다고 말하고 있습니다. 현재 로그인 기능을 게시하면 내가 의미하는 바를 정확히 보여줄 수 있습니다. – DoesData