Chr*_*ris 8 ios firebase firebase-authentication flutter apple-sign-in
我已经实施了Sign-In-With-Applewith Firebase. 我还有删除用户的功能。这就是我所做的:
static Future<bool> deleteUser(BuildContext context) async {
try {
await BackendService().deleteUser(
context,
);
await currentUser!.delete(); // <-- this actually deleting the user from Auth
Provider.of<DataProvider>(context, listen: false).reset();
return true;
} on FirebaseException catch (error) {
print(error.message);
AlertService.showSnackBar(
title: 'Fehler',
description: error.message ?? 'Unbekannter Fehler',
isSuccess: false,
);
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我删除了所有用户数据,最后删除了用户本人auth。
但苹果仍然认为我正在使用该应用程序。我可以在我的设置中看到它:
此外,当尝试再次使用苹果登录时,它就像我已经有一个帐户一样。但我刚刚删除了它,Firebase 中没有任何内容表明我仍然拥有该帐户?如何从 Firebase 中彻底删除 Apple 用户?我在这里缺少什么?
Chr*_*ris -1
所以...苹果不提供这项服务。但就我而言,以下解决方法效果很好。
我的登录流程:
1. 检查用户之前是否登录过
// Create an `OAuthCredential` from the credential returned by Apple.
final oauthCredential = OAuthProvider("apple.com").credential(
idToken: appleCredential.identityToken,
rawNonce: rawNonce,
);
// If you can not access the email property in credential,
// means that user already signed in with his appleId in the application once before
bool isAlreadyRegistered = appleCredential.email == null;
Run Code Online (Sandbox Code Playgroud)
现在到关键部分:
2.登录用户并检查uidFirebase中是否已存在
final UserCredential result =
await FirebaseAuth.instance.signInWithCredential(
oauthCredential,
);
isAlreadyRegistered = await BackendService.checkIfUserIdExists(
result.user?.uid ?? '',
);
Run Code Online (Sandbox Code Playgroud)
checkIfUserIdExists也很简单:
static Future<bool> checkIfUserIdExists(String userId) async {
try {
var collectionRef = FirebaseFirestore.instance.collection(
BackendKeys.users,
);
var doc = await collectionRef.doc(userId).get();
return doc.exists;
} on FirebaseException catch (e) {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2277 次 |
| 最近记录: |