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