2016-12-16 1 views
0

계정 키트를 사용 중이며 firebase에 [email protected]을 저장해야합니다. 그래서 나는 그들의 이메일과 패스워드 흐름을 가지고 노력했다. 그러나 내가 발견 한 문제는 두 가지 다른 흐름이 있다는 것입니다. 하나는 사용자를 생성하는 것이며, 하나는 register- createUserWithEmailAndPassword 및 다른 사용자가 로그인 할 때 로그인 할 때 시작해야하는 로그인 흐름에서 시작됩니다. 이미 생성 된 -signInUserWithEmailAndPassword.로그인 및 가입과 동일한 흐름 : Firebase Auth

동일한 생성 및 로그인 호출과 같은 기능이있어 처음 사용자인지 여부를 판단 할 수 있으므로 기존 사용자 또는 기존 사용자를 만드십시오.

나는 내 서버 검사를 할 수 있지만 지연과 다른 시스템에 대한 다중 호출을 초래합니다.

+0

'createUserWithEmailAndPassword'를 호출하면 해당 사용자가 로그인되면 로그인하고 해당 이메일 주소를 가진 사용자가 이미 존재하면 실패합니다. –

답변

0

는 다음을 수행 할 수 있습니다 :

firebase.auth().fetchProvidersForEmail(email) 
    .then(function(providers) { 
     if (providers.length > 0) { 
     // The user has already been registered. Careful though: the 
     // following assumes that your users only sign up with email 
     // and password. If they can sign up with other providers 
     // (Google, Facebook...), you may not be able to do the next 
     // call. 
     return firebase.auth().signInWithEmailAndPassword(
      email, password); 
     } else { 
     // No account exists with this email address. 
     return firebase.auth().createUserWithEmailAndPassword(
      email, password); 
    }).then(function(user) { 
     // User is signed in! 
    }); 

이 먼저 해당 이메일 주소에 링크 된 업체를 확인됩니다. 목록이 비어 있지 않고 사용자가 이메일 및 비밀번호로만 가입 할 수 있으면 (Google 로그인, Facebook 로그인 등) 사용자가 이미 이메일과 비밀번호로 가입했음을 보증합니다. 이 경우 사용자에게 로그인 할 수 있습니다. 목록이 비어 있으면 사용자가 존재하지 않으며 새 사용자를 만들 수 있습니다.

질문에 대한 답변이 있습니까?