如何访问 Google 用户名以进行 flutter 身份验证。点燃 Firebase 身份验证
How to access Google username for flutter authentication. Lit Firebase Auth
我对此有点陌生,但我对如何在使用 Google 登录时访问用户的 Google 用户名感到困惑。我使用了 Lit Firebase Auth,所以基本上我只需要说
context.signInWithGoogle();
但是我需要一个显示名称,就像在我的数据库中一样,当用户使用电子邮件注册时,他们可以输入用户名,通过该用户名,他们输入的文本将被存储,然后显示为他们的用户名。
这是我的 register.dart
try {
await Firebase.initializeApp();
UserCredential user = await FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: _emailController.text,
password: _passwordController.text,
);
User updateUser = FirebaseAuth.instance.currentUser;
updateUser.updateProfile(
displayName: _usernameController.text);
userSetup(_usernameController.text);
Navigator.of(context).pushAndRemoveUntil(
HomeScreen.route, (route) => false);
}
而重要的部分是
userSetup
将从我的数据库中获取该文本并更新显示名称。
所以我想我问的是在 Google 登录的情况下填充 userSetup() 而不是 _usernameController.text。
您可以尝试以下代码,用于 google 登录 flutter 并从 google 获取凭据并将它们用于 firebase,变量 user 包含所有用户信息,如电子邮件、imageurl 和名字.
GoogleSignIn _googleSignIn = new GoogleSignIn();
GoogleSignInAccount googleSignInAccount = await _googleSignIn.signIn();
GoogleSignInAuthentication googleSignInAuthentication = await googleSignInAccount.authentication;
AuthCredential credential = GoogleAuthProvider.credential(idToken: googleSignInAuthentication.idToken, accessToken: googleSignInAuthentication.accessToken);
var result = (await _auth.signInWithCredential(credential));
_user = result.user;
我对此有点陌生,但我对如何在使用 Google 登录时访问用户的 Google 用户名感到困惑。我使用了 Lit Firebase Auth,所以基本上我只需要说
context.signInWithGoogle();
但是我需要一个显示名称,就像在我的数据库中一样,当用户使用电子邮件注册时,他们可以输入用户名,通过该用户名,他们输入的文本将被存储,然后显示为他们的用户名。
这是我的 register.dart
try {
await Firebase.initializeApp();
UserCredential user = await FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: _emailController.text,
password: _passwordController.text,
);
User updateUser = FirebaseAuth.instance.currentUser;
updateUser.updateProfile(
displayName: _usernameController.text);
userSetup(_usernameController.text);
Navigator.of(context).pushAndRemoveUntil(
HomeScreen.route, (route) => false);
}
而重要的部分是
userSetup
将从我的数据库中获取该文本并更新显示名称。
所以我想我问的是在 Google 登录的情况下填充 userSetup() 而不是 _usernameController.text。
您可以尝试以下代码,用于 google 登录 flutter 并从 google 获取凭据并将它们用于 firebase,变量 user 包含所有用户信息,如电子邮件、imageurl 和名字.
GoogleSignIn _googleSignIn = new GoogleSignIn();
GoogleSignInAccount googleSignInAccount = await _googleSignIn.signIn();
GoogleSignInAuthentication googleSignInAuthentication = await googleSignInAccount.authentication;
AuthCredential credential = GoogleAuthProvider.credential(idToken: googleSignInAuthentication.idToken, accessToken: googleSignInAuthentication.accessToken);
var result = (await _auth.signInWithCredential(credential));
_user = result.user;