SwiftUI中Firebase Auth删除Google注册用户时报错“This operation is restricted to administrators only”的问题求助
SwiftUI中Firebase Auth删除Google注册用户时报错“This operation is restricted to administrators only”的问题求助
各位开发者好,我目前在SwiftUI项目中遇到了Firebase Auth的用户删除问题:
当我尝试删除通过Google账号注册的Firebase用户时,会收到错误提示:This operation is restricted to administrators only,但删除通过邮箱密码注册的用户却完全正常。这个Google账号是用户通过Firebase iOS SDK正常注册的,并非后台创建的管理员账号。
以下是我实现的删除Google注册用户的代码:
func deleteUser(completion: @escaping(String) -> Void) { guard let currentUser = Auth.auth().currentUser else { completion("User auth error!") return } guard let clientID = FirebaseApp.app()?.options.clientID else { completion("Cloud error occured!") return } // Get the correct windowScene guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, let rootVC = windowScene.windows.first?.rootViewController else { completion("An internal error occured") return } let config = GIDConfiguration(clientID: clientID) GIDSignIn.sharedInstance.signIn(withPresenting: rootVC) { signInResult, error in if let error = error { completion("An error occured in verification") return } guard let idToken = signInResult?.user.idToken?.tokenString, let accessToken = signInResult?.user.accessToken.tokenString else { completion("Missing authentication tokens.") return } let credential = GoogleAuthProvider.credential(withIDToken: idToken, accessToken: accessToken) currentUser.reauthenticate(with: credential) { _, error in if let error = error { completion("Reauthentication failed, try again later") return } currentUser.delete { error in if let error = error { print(error.localizedDescription) // 此处触发错误 completion("Failed to delete user") } else { completion("") } } } } }
我已经按照Firebase的要求,在删除前做了重新认证的步骤:调用reauthenticate(with:)方法,传入了Google的认证凭证,但还是触发了这个管理员权限的错误。
想请教各位:
- 这个错误可能的原因是什么?
- 我的代码逻辑中有没有哪里处理不当?
- 有没有其他可行的解决思路?
内容来源于stack exchange
相关产品推荐
相关产品推荐

