Firebase Facebook登录检查用户是否存在 [英] Firebase Facebook login check if user exist

查看:200
本文介绍了Firebase Facebook登录检查用户是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与firebase一起工作的facebook登录系统,但是我想检查用户是否存在于我的firebase上(我不想添加它,只想确定他是否存在,因为我想将用户重定向到另一个页面来完成它的个人资料,一旦完成,我想把它发送到firebase)。

我只需要检查用户是否存在我的数据库。这是我尝试的代码,但它返回nil错误,并自动将用户添加到firebase。

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


FIRAuth.auth()?。signInWithCredential(凭证){(user,error)in
// ...


$ / code $ / $ p

解决方案

code> reauthenticateWithCredential 方法检查用户是否存在。

检查此文档,section - >重新认证用户

$ p $ let user = FIRAuth.auth()?currentUser
var凭证:FIRAuthCredential

提示用户重新提供登录凭据

用户?.reauthenticateWithCredential(凭证){
中的错误,如果让错误=错误{
//发生错误。
} else {
//用户重新认证。






如果用户重新认证成功意味着用户存在...


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
        // ... 

}

解决方案

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...

这篇关于Firebase Facebook登录检查用户是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆