【发布时间】:2018-11-18 05:32:41
【问题描述】:
我有一个应用程序允许用户创建新帐户或通过 facebook/Google 登录。一些次要数据(如配置文件名称等)存储在用户默认值中。我正在使用 Firebase 进行登录。
问题:在用户 A 退出其帐户并且用户 B 登录后,用户 A 的数据(保存到用户默认值)对用户 B 可见。
我想要的:显然这不应该发生,用户 B Should not 看到用户 A 的数据。我怎样才能做到这一点?
退出代码
@IBAction func logout(_ sender: Any) {
if Auth.auth().currentUser != nil {
do {
try Auth.auth().signOut()
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Login")
present(vc, animated: true, completion: nil)
} catch let error as NSError {
print(error.localizedDescription)
}
}else {
GIDSignIn.sharedInstance()?.signOut()
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Login")
present(vc, animated: true, completion: nil)
}
let firebaseAuth = Auth.auth()
do {
print("logged out success!")
try firebaseAuth.signOut()
} catch let signOutError as NSError {
print ("Error signing out: %@", signOutError)
}
}
编辑: 我刚刚开始将 UID 存储到 userdefaults 中。
【问题讨论】:
-
将用户的电子邮件添加到默认字典中的键中
-
@palebone 感谢您的回复。你能告诉我你的意思吗?
-
这里的简单解决方案是不要在 UserDefaults 中存储这样的数据;将其存储在 Firebase 中。当用户进行身份验证时,从 Firebase 数据库中读取您需要的任何数据,然后您就完成了。如果您使用 UserDefaults,当用户在不同的设备上登录时,他们将没有默认设置 - 将其存储在 FB 中可以让用户随心移动。
标签: swift firebase firebase-authentication nsuserdefaults