gpt4 book ai didi

ios - 在ios上创建Firebase用户而不自动登录

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

我正在编写一个以 firebase 作为后端的 ios 应用程序。在我的应用程序中,有一些管理员应该能够创建新用户。新用户不应该能够自己创建帐户。

在网络上,我正在使用该功能

ref.createUser({
email: ctrl.user.email,
password: ctrl.user.password
}, function(error, userData) { // }

使用随 secret 码,然后重置密码。因此,用户将收到一封包含密码重置链接的电子邮件,然后可以设置新密码并登录。创建用户后,我将所有相关的用户数据存储到数据库中。

在 ios 上,我尝试创建一个新用户:

FIRAuth.auth()?.createUser(withEmail: email, password: password) { (user, error) in }

但是如果我这样做,我会使用我的管理员帐户注销并使用我新创建的帐户登录。因此,我无法将用户数据存储到数据库中,因为这仅限于管理员......

ios 有没有办法只创建一个用户,而不使用该用户自动登录?

最美好的祝愿

托比

编辑我使用适用于 Node.js 的 firebase admin sdk 编写了一个 AWS lambda 函数,并在该函数内创建用户,并通过我的 ios 应用程序中的 Web 服务调用触发该函数。不完美,但正在工作......

最佳答案

是的,调用createUser(withEmail:,password:)将登录新用户。为了实现您想要做的事情,我建议通过执行以下操作来解决方法(假设当前管理员已登录):

// Create the values
var email = alreadySelectedUserEmail
var password = arc4random_uniform(1000000) // or another random number

// Send the information to the database
FIRDatabase.database().reference().child("user_data").child(email) .
setValue("lorem ipsum") // or another value

// THEN create the user, AFTER sending the data
// This will automatically log you in to the new account
FIRAuth.auth()?.createUser(withEmail: email,
password: password) { (user, error) in
// Check for any errors
if let error = error {
print error
} else {
// If there are none, LOG OUT…
try! FIRAuth.auth()!.signOut()

// …and log back into Admin (with whatever login info they have)
FIRAuth.auth()?.signIn(withEmail: adminEmail,
password: adminPassword) { (user, error) in
// Check for any errors
if let error = error {
print error
} else {
// All done, new account created!
}
}
}

关于ios - 在ios上创建Firebase用户而不自动登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40790238/

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