swift - SwiftUI - 重新验证用户凭据 (FireStore)
问题描述
好的,所以我在网上查看,甚至阅读了谷歌提供的文件,但是,我似乎无法弄清楚我哪里出错了。
我想更改一个帐户的密码。这是我现在的代码:
var credential: AuthCredential!
let user = Auth.auth().currentUser
VStack {
Text("Enter new password").font(.caption).foregroundColor(Color(SYSTEM_FONT_COLOUR))
PasswordTextField(password: $changeLoginDetailsViewModel.newPassword)
Spacer()
SignInButton(action: {
self.user?.reauthenticate(with: self.credential) { (result, error) in
if let error = error {
print(error.localizedDescription)
}
}
self.changeLoginDetailsViewModel.changePassword()
}, label: "Update Password")
}
每次我点击"Update password"
按钮时,应用程序都会崩溃。那是因为credential
是零。所以我做了我的研究并找到了方法EmailAuthProvider()
。所以我添加了这行代码:
let email = EmailAuthProvider.credential(withEmail: (Auth.auth().currentUser?.email!)!, password: "thisIsNotTheRealPassword")
出于道德原因和最佳实践,我不在我的数据库中存储用户密码。那么我什至如何获取/访问当前用户的密码呢?不保存?
我想我可以让用户输入他们当前的密码,这将允许重新身份验证,但是有没有一种方法可以在视图加载时做到这一点?所以他们不需要按两次更新密码按钮?并获得更好的 UI 体验。他们的用户已经登录,除非他们退出,否则不需要登录。
解决方案
好的,所以为了确保我始终对用户进行身份验证,我要求用户在有机会/查看更新他们的凭据之前输入他们的登录凭据。
我的解决方案:
Settings > Re-authentication view (explained to the user it's for security purposes) > Change password and e-mail view
推荐阅读
- nopcommerce - 暂时无法评分,请稍后再试。Nop Commerce 4.2 fedex 插件问题
- google-analytics - 谷歌分析 - 添加分析标签值
- r - 在 forestplot R 函数中更改 x 轴标签的字体大小
- java - Liquibase 和系统目录 (PostgreSQL)
- javascript - 当用户缩小时增加 Konva.js 地图中的文本大小
- python - 如何将 RGBA 图像转换为 RGB 并将其提供给 Keras 中经过训练的 CNN?
- terraform - 从 Terraform 0.11 升级到 0.12 期间的列表问题
- javascript - 在 VueJS 中使用 setAttribute 切换 @click
- python - coreapi:无法获取架构
- asp.net-core - asp net core mvc中的垂直线