Firebase Facebook login check if user exist

杀马特。学长 韩版系。学妹 提交于 2019-12-09 01:28:31

问题


I have an facebook login system which works with firebase but I want to check if user exist on my firebase (i don't want to add it, just want to make sure if he exist because I want to redirect user to another page to complete its profile, once its done I'll want to send it to firebase).

I just need to check if user exist on my db. Here is the code that I try but it returns nil error and it automatically add user to firebase.

let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)


FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
        // ... 

}

回答1:


You can use reauthenticateWithCredential method to check user is exist or not.

Check this Doc. , section -> Re-authenticate a user

let user = FIRAuth.auth()?.currentUser
var credential: FIRAuthCredential

// Prompt the user to re-provide their sign-in credentials

user?.reauthenticateWithCredential(credential) { error in
  if let error = error {
    // An error happened.
  } else {
    // User re-authenticated.
  }
}

If user re-authenticated successfully that means user is existed...



来源:https://stackoverflow.com/questions/38435080/firebase-facebook-login-check-if-user-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!