如何使用firebase快速合并自定义登录(电子邮件)与Facebook登录 [英] How to merge custom login (Email) with Facebook login in swift using firebase

查看:181
本文介绍了如何使用firebase快速合并自定义登录(电子邮件)与Facebook登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase快速实施自定义(电子邮件)和Facebook登录身份验证。因为,我为每个电子邮件地址启用了多个帐户,同一个用户使用他的电子邮件以及他的Facebook帐户可以登录到应用程序。 Firebase将其视为两个单独的用户,但只要电子邮件地址相同,我想合并它们。我从Facebook网站上找到这个
链接这解释了我试图解决的情况。我正在寻找任何代码示例如何做。

在此先感谢。

解决方案

Firebase实际上相当简单。下面的代码应该工作,我也包括一个链接到描述该过程的文档。

  let credential = FacebookAuthProvider.credential withAccessToken:
FBSDKAccessToken.current()。tokenString)
$ b $ if let user = FIRAuth.auth()?currentUser {
user.link(with:credential){ ,错误)in
//在帐户被链接之后执行任何操作


$ b $ $
$ b

以下是关于此主题的Firebase文档的链接:
https://firebase.google.com/docs/auth/ios/account-linking


I am implementing custom (Email) and Facebook login authentication in swift using Firebase. Since, I enabled multiple accounts per email address, a same user using his email as well as his facebook account can sign in to the app. Firebase considers them as two separate users, but I want to merge them as long as the email address is same. I found this link from the Facebook site which explain the scenario which i am trying to solve. I am looking for any code samples on how to do.

Thanks in advance.

解决方案

This is actually quite simple with Firebase. The below code should work and I have also included a link to the documentation describing the process.

let credential = FacebookAuthProvider.credential(withAccessToken: 
FBSDKAccessToken.current().tokenString)

if let user = FIRAuth.auth()?.currentUser {
   user.link(with: credential) { (user, error) in
      //perform any actions after the account has been linked
   }
}

Here is a link to the Firebase documentation on the subject: https://firebase.google.com/docs/auth/ios/account-linking

这篇关于如何使用firebase快速合并自定义登录(电子邮件)与Facebook登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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