gpt4 book ai didi

ios - 使用新的 firebase 登录后不会加载用户信息。 iOS

转载 作者:行者123 更新时间:2023-11-28 07:49:14 24 4
gpt4 key购买 nike

我是编程新手,仍在学习 Swift 语言。

我希望你能帮我解决这个问题。

当我尝试注册时,用户信息显示在数据库中,但当我尝试登录时,用户信息却消失了,这是为什么?想不通。

这是我注册的方式

@objc func handleSignUp() {

guard let username = usernameField.text else { return }

guard let email = emailField.text else { return }

guard let pass = passwordField.text else { return }

guard let image = profileImageView.image else { return }

setContinueButton(enabled: false)
continueButton.setTitle("", for: .normal)
activityView.startAnimating()
Auth.auth().createUser(withEmail: email, password: pass) { user, error in

if error == nil && user != nil {
print("User created!")


// 1. Upload the profile image to Firebase Storage

self.uploadProfileImage(image) { url in
if url != nil {
let changeRequest = Auth.auth().currentUser?.createProfileChangeRequest()
changeRequest?.displayName = username
changeRequest?.photoURL = url
changeRequest?.commitChanges { error in

if error == nil {
print("User display name changed!")

self.saveProfile(username: username, profileImageURL: url!) { success in
if success {
self.dismiss(animated: true, completion: nil)
} else {
self.resetForm()
}
}
} else {
print("Error: \(error!.localizedDescription)")
self.resetForm()
}
}
} else {
self.resetForm()
}
}
} else {
self.resetForm()
}
}
}

这是我登录的方式

@objc func handleSignIn() {


guard let email = emailField.text else { return }
guard let pass = passwordField.text else { return }


setContinueButton(enabled: false)
continueButton.setTitle("", for: .normal)
activityView.startAnimating()

Auth.auth().signIn(withEmail: email, password: pass) { user, error in

if error == nil && user != nil {

self.dismiss(animated: false, completion: nil)

_ = Auth.auth().currentUser

} else {
print("Error logging in: \(error!.localizedDescription)")

self.resetForm()
}
}

我不知道是什么问题

最佳答案

我不熟悉 firebase,但根据他们的文档,这是“da way”:

Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
if let error = error {
print("ERROR [ signIn ] => \(error)")
// self.resetForm()
} else {
if let user = user {
let uid = user.uid
let email = user.email
print("Authorised User => \(uid) ... \(email)")
}
}
}

如果在尝试上面的代码后你看到这个输出 ERROR [ signIn ] => whatever error...",那么你的登录失败了。如果你看到这个输出 Authorised User => SomeUID ... SomeEMAIL,那么你登录成功,你的用户数据还在数据库中。

我希望这能帮助你找到“da way”

如果一切都失败了:

您可以更换浏览器并再次检查您的数据库吗?尝试几个浏览器。这适用于 some people

祝你好运!

关于ios - 使用新的 firebase 登录后不会加载用户信息。 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50126476/

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