简体   繁体   English

Flutter-无法使用Firebase Auth登录

[英]Flutter - Unable to signin with Firebase Auth

My Android Flutter app has Google sign-in using Firebase Authentication. 我的Android Flutter应用程序具有使用Firebase身份验证的Google登录。 Everything works great in debug mode, but fails in release mode. 一切都在调试模式下运行良好,但在发布模式下失败。 I have added my SHA-1 fingerprints for both debug and release keystores in the Firebase console, and have updated to the latest google-services.json. 我已经在Firebase控制台中为调试和发布密钥库添加了SHA-1指纹,并且已更新为最新的google-services.json。

The problem seems to be that I am never getting a FirebaseUser back. 问题似乎是我再也找不到FirebaseUser了。 This method always returns null: 此方法始终返回null:

Future<FirebaseUser> _getCurrentUser() async {
  FirebaseAuth firebaseAuth = FirebaseAuth.instance;
  if (firebaseAuth.currentUser() != null) {
    return await firebaseAuth.currentUser();
  }

  return null;
}

The codelabs example isn't working either. codelabs示例也不起作用。 It is returning a GoogleSignInUser, but it's not creating a Firebase user in the console: 它正在返回GoogleSignInUser,但未在控制台中创建Firebase用户:

Future<GoogleSignInAccount> _ensureLoggedIn() async {
  GoogleSignInAccount user = _googleSignIn.currentUser;
  if (user == null) user = await _googleSignIn.signInSilently();
  if (user == null) {
    user = await _googleSignIn.signIn();
    analytics.logLogin();
  }
  if (_auth.currentUser == null) {
    GoogleSignInAuthentication credentials =
        await _googleSignIn.currentUser.authentication;
    await _auth.signInWithGoogle(
      idToken: credentials.idToken,
      accessToken: credentials.accessToken,
    );
  }

  return user;
}

I have implemented Firebase Authentication before in a native Android app just fine. 在本地Android应用中,我之前已经实现了Firebase身份验证。 I have read several other stack overflow posts about this, but I feel like I have tried everything. 我已经读过其他有关此问题的堆栈溢出文章,但是我觉得我已经尝试了一切。 Any help would be appreciated! 任何帮助,将不胜感激!

UPDATE: 更新:

In a release build, I can read and write to the database if I don't set any read/write rules. 在发布版本中,如果未设置任何读/写规则,则可以读写数据库。 I am still unable to create a FirebaseUser. 我仍然无法创建FirebaseUser。 I can create a GoogleSignInAccount, but that doesn't create a Firebase user. 我可以创建一个GoogleSignInAccount,但是不能创建Firebase用户。

I managed to get it working. 我设法使它起作用。 I just updated all of my dependencies to the latest versions and targeted the latest version of android, then updated my project using this guide and authenticated with Firebase the same way as in this example . 我只是将所有依赖项更新为最新版本,并以最新版本的android为目标,然后使用本指南更新了我的项目,并以与本示例相同的方式通过Firebase进行了身份验证。

These are my dependencies: 这些是我的依赖项:

google_sign_in: 2.0.0
firebase_analytics: 0.2.0
firebase_auth: 0.4.0
firebase_database: 0.3.1
firebase_admob: 0.2.2

Hope this helps somebody! 希望这对某人有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM