如何将UserCredential转换为User-Flutter



你好,我有这个功能可以登录facebook,但它返回了一个UserCredential,是否可以从firebase_auth包将其转换为User

Future<UserCredential> facebook() async {
try {
final AccessToken accessToken = await FacebookAuth.instance.login();
// Create a credential from the access token
final FacebookAuthCredential credential = FacebookAuthProvider.credential(
accessToken.token,
);
// Once signed in, return the UserCredential
UserCredential authResult =
await _firebaseAuth.signInWithCredential(credential);
} on FacebookAuthException catch (e) {
// handle the FacebookAuthException
} on FirebaseAuthException catch (e) {
// handle the FirebaseAuthException
} finally {}
return null; 
}

UserCredential实际上有一个用于User的getter。

final AccessToken accessToken = await FacebookAuth.instance.login();
final AuthCredential credential =
FacebookAuthProvider.getCredential(accessToken: accessToken.token);
final firebaseUser = (await auth.signInWithCredential(credential)).user;

相关内容

  • 没有找到相关文章

最新更新