Authenticating with Database Secrets in Firebase SDK v3?

最后都变了- 提交于 2019-12-10 18:04:13

问题


First of all, I'm loving the new Firebase. However, I can't get my Swift project to connect to Firebase since I'm using database secrets to authenticate devices.

Before the version 3 of the Firebase SDK, I was able authenticate to access my database using Firebase secrets (now Database secrets). I was able to do this using the following block of code:

ref.authWithCustomToken("authKeyHere", withCompletionBlock: { error, authData in
   if error != nil {
      print("Login failed! \(error)")
    } else {
      print("Login to firebase succeeded! \(authData)")
    }
})

This worked great for me since I'm only authenticating users of my app and not making the whole database public, so to speak.

I'm trying to achieve the same thing with the new Firebase SDK (v3). I have added the necessary pods to my project and as far as I can see, I would need to use the following code to achieve the same thing:

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)
   }
}

However, when this code runs, all I get is the following error printed to the logs:

The custom token format is incorrect. Please check the documentation.

So my question is: What am I doing wrong? If you need any more information, I'm happy to give it you :)

来源:https://stackoverflow.com/questions/37940058/authenticating-with-database-secrets-in-firebase-sdk-v3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!