首先,我喜欢新的 Firebase。但是,我无法让我的 Swift 项目连接到 Firebase,因为我使用数据库机密来验证设备。
在 Firebase SDK 版本 3 之前,我可以使用 Firebase 密钥(现在是数据库密钥)进行身份验证以访问我的数据库。我能够使用以下代码块来做到这一点:
ref.authWithCustomToken("authKeyHere", withCompletionBlock: { error, authData in
if error != nil {
print("Login failed! \(error)")
} else {
print("Login to firebase succeeded! \(authData)")
}
})
这对我来说非常有用,因为我只是对我的应用程序的用户进行身份验证,而不是公开整个数据库,可以这么说。
我正在尝试使用新的 Firebase SDK (v3) 实现同样的目标。我已将必要的 pod 添加到我的项目中,据我所知,我需要使用以下代码来实现相同的功能:
FIRApp.configure()
FIRAuth.auth()?.signInWithCustomToken("authKeyHere") { (user, error) in
//This signs in using the authentication secret so we can now access the database.
if error != nil {
print(error?.localizedDescription)
} else {
print(user?.uid)
}
}
但是,当此代码运行时,我得到的只是打印到日志中的以下错误:
自定义令牌格式不正确。请检查文档。
所以我的问题是:我做错了什么?如果您需要更多信息,我很乐意为您提供:)