Issue
I noticed such a problem that sometimes don't log in to Google account. In the release or debug build, the auth works, but this error often pops up. This problem did not exist before with the same configuration.
I/flutter (16382): [firebase_auth/invalid-credential] The supplied auth credential is malformed or has expired. [ Invalid Idp Response: access_token
audience is not for this project ]
E/flutter (16382): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: NoSuchMethodError: The getter 'user' was called on null.
E/flutter (16382): Receiver: null
E/flutter (16382): Tried calling: user
E/flutter (16382): #0 signInWithGoogle (package:dp/workers/auth.dart:37)
E/flutter (16382): <asynchronous suspension>
E/flutter (16382): #1 _MyHomePageState.build.onDocking (package:dp/main.dart:247)
E/flutter (16382): <asynchronous suspension>
E/flutter (16382):
Code:
final FirebaseAuth _auth = FirebaseAuth.instance;
Future<String> signInWithGoogle() async {
// Trigger the authentication flow
final GoogleSignInAccount googleSignInUser = await GoogleSignIn().signIn();
// Obtain the auth details from the request
final GoogleSignInAuthentication googleAuth =
await googleSignInUser.authentication;
// Create a new credential
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
UserCredential authResult;
try {
// Attempt to sign in the user in with Google
authResult = await _auth.signInWithCredential(credential);
} on FirebaseAuthException catch (e) {
print(e);
}
final User user = authResult.user;
assert(user.email != null);
assert(user.displayName != null);
assert(user.photoURL != null);
assert(!user.isAnonymous);
assert(await user.getIdToken() != null);
final User currentUser = _auth.currentUser;
assert(user.uid == currentUser.uid);
final DatabaseServiceUser db = DatabaseServiceUser();
await db.createUser(currentUser);
return 'signInWithGoogle succeeded: $user';
}
pubspec.yaml:
google_sign_in: ^5.0.1
firebase_auth: ^1.4.1
flutter doctor -v:
[√] Flutter (Channel stable, 2.2.2, on Microsoft Windows [Version 10.0.17763.1935], locale ru-RU)
• Flutter version 2.2.2 at D:\FLUTTER
• Framework revision d79295af24 (3 weeks ago), 2021-06-11 08:56:01 -0700
• Engine revision 91c9fc8fe0
• Dart version 2.13.3
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at D:\SDK
• Platform android-30, build-tools 30.0.3
• Java binary at: C:\Program Files\Java\jre1.8.0_291\bin\java
• Java version Java(TM) SE Runtime Environment (build 1.8.0_291-b10)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).
[√] Connected device (1 available)
• Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.114
! Doctor found issues in 1 category.
OAuth consent screen and credentials p: OAuth consent screen pic Credentials pic
Solution
The error turned out to be on Google's side. After creating a new project in firebase, everything worked successfully with the same configuration as in the past.
Answered By - t-geh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.