首先,我喜欢新的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)
}
}
但是,当此代码运行时,我得到的是以下错误打印到日志:
自定义令牌格式不正确。请查看文档。
所以我的问题是:我做错了什么?如果您需要更多信息,我很高兴为您提供:)