Ron*_*ton 6 firebase firebase-authentication
文档将匿名帐户转换为永久帐户指出了该过程的 3 个步骤,但步骤 2 似乎违反了步骤 1。
- 当用户注册时,完成用户身份验证提供程序的登录流程,直到(但不包括)调用 Auth.signInWith 方法之一。例如,获取用户的 Google ID 令牌、Facebook 访问令牌或电子邮件地址和密码。
- 获取新身份验证提供程序的 AuthCredential:
var credential = firebase.auth.FacebookAuthProvider.credential( response.authResponse.accessToken);- 将 AuthCredential 对象传递给登录用户的链接方法...
我的问题是:步骤 2.仅在调用步骤 1不执行的方法之一后才response存在。如何将匿名帐户与 oAuth 帐户关联?Auth.signInWith
文档所说的是,在步骤 1 中,您不应使用 Firebase 登录。步骤 1 的意思是,您应该使用提供商(即 Google、Facebook、Twitter)登录,然后获取提供商令牌,然后将提供商令牌链接到现有 Firebase 匿名帐户或使用提供商令牌登录 Firebase。重要的是,文档引用的令牌来自提供商,而不是 Firebase。
您没有指定计划使用哪种语言/平台执行此操作,但这只是 Dart/Flutter 的示例:
GoogleSignInAccount googleUser = await _googleSignIn.signIn();
// Get the provider auth token
GoogleSignInAuthentication googleAuth = await googleUser.authentication;
FirebaseUser user = await _auth.currentUser();
// Check if the user has signed in as anonymous
if (user != null) {
// Use the provider auth token to link the anonymous account
await _auth.linkWithGoogleCredential(
accessToken: googleAuth.accessToken, idToken: googleAuth.idToken);
} else if (user == null || user.email == null) {
user = await _auth.signInWithGoogle(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
}
Run Code Online (Sandbox Code Playgroud)