使用Firebase Google Auth,当用户使用其Google帐户成功登录时,它们不会显示在我们的Firebase控制台身份验证 - >用户屏幕上。只有电子邮件/密码用户出现在那里。
为了查看Google Auth用户,还需要做些额外的工作吗?
答案 0 :(得分:4)
如Frank所示,要完全登录Firebase,需要调用signInWithCredential()。实施此功能后,使用Google登录的用户会显示在Firebase控制台中。
答案 1 :(得分:4)
在Flutter中,除了GoogleSignIn之外,您还需要安装firebase_auth软件包。
https://pub.dev/packages/firebase_auth#-installing-tab-
https://pub.dev/packages/firebase_auth
import 'package:firebase_auth/firebase_auth.dart';
final GoogleSignIn _googleSignIn = GoogleSignIn();
final FirebaseAuth _auth = FirebaseAuth.instance;
Future<FirebaseUser> _handleSignIn() async {
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final FirebaseUser user = (await _auth.signInWithCredential(credential)).user;
print("signed in " + user.displayName);
return user;
}
...
_handleSignIn()
.then((FirebaseUser user) => print(user))
.catchError((e) => print(e));
答案 2 :(得分:0)
请按照以下步骤操作:
final GoogleSignInAccount googleUser = await GoogleSignIn().signIn();
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final GoogleAuthCredential googleCredential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final UserCredential googleUserCredential =
await FirebaseAuth.instance.signInWithCredential(googleCredential);
就是这样!!