gpt4 book ai didi

swift - Firebase AuthUI 对于“使用 Apple 登录”中的显示名称和电子邮件返回 nil

转载 作者:行者123 更新时间:2023-11-30 10:25:33 24 4
gpt4 key购买 nike

当我尝试使用 Apple 登录时,Firebase AuthUI 对于显示名称和电子邮件返回 nil。这是我的代码

lazy var authUI: FUIAuth? = {
let UIAuth = FUIAuth.defaultAuthUI()
UIAuth?.delegate = self
UIAuth?.shouldHideCancelButton = true
return UIAuth
}()
func presentLogin(){
// providers
var providers: [FUIAuthProvider] = [
FUIEmailAuth(),
FUIGoogleAuth(),
FUIFacebookAuth()
]

if #available(iOS 13.0, *) {
let appleProvider = FUIOAuth.appleAuthProvider()
providers.append(appleProvider)
}

self.authUI?.providers = providers
let loginController = self.authUI!.authViewController()
present(loginController, animated: true, completion: nil)
}

func authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, error: Error?) {
print(authDataResult?.user.displayName)
}

最佳答案

我也遇到了同样的问题!我没有登录 Apple,但即使仅使用 Firebase,此信息也会显示为零。我的问题是我没有正确设置 Firebase 和 Xcode 进行通信的数据。您的代码似乎是正确的,但看起来您可能遗漏了一些东西..?你比我更有经验,所以我可能是错的!但这是我的代码...

   // SIGN UP FUNCTION, first name, last name, email, password
let db = Database.database().reference()
func signUp(firstName: String, lastName: String, email: String, password: String, completion: @escaping (LocalUser?, Error?) -> Void) {
let usersRef = db.child("users")
Auth.auth().createUser(withEmail: email, password: password) {[weak self] (result, error) in

if let uid = result?.user.uid {
let newUser: [String: String] = ["firstName": firstName, "lastName": lastName, "email": email]
let newLocalUser = LocalUser(firstName: firstName, lastName: lastName, email: email)
usersRef.child(uid).setValue(newUser){(error: Error?, ref: DatabaseReference) in
completion(newLocalUser, error)
}
} else {
completion(nil, nil)
}
}
}

// SIGN IN FUNCTION, email, password
func signIn(email: String, password: String, completion: @escaping (LocalUser?, Error?) -> Void) {
let usersRef = db.child("users")
Auth.auth().signIn(withEmail: email, password: password) { [weak self]
(result, error) in
guard let user = result?.user else {
completion(nil, error)
return
}

let uid = user.uid

usersRef.child(uid).observeSingleEvent(of: .value) { (snapshot) in
let value = snapshot.value as? [String: Any]
if let user = value {
let userObject = LocalUser.makeObjectFrom(user)
newUser = userObject
completion(userObject, nil)
} else {
completion(nil, error)
}
}
}
}

我没有看到对 dbuid 的引用,所以这可能会有所帮助!

关于swift - Firebase AuthUI 对于“使用 Apple 登录”中的显示名称和电子邮件返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60078412/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com