"firebase.auth(...).verifyIdToken is not a function"

2,936 views
Skip to first unread message

Mark Pfeffer

unread,
Sep 13, 2016, 12:30:26 AM9/13/16
to Firebase Google Group
Hi,

I'm trying to authenticate users on my node app by sending a token from my client to my server.


Here is my client-side code: 
$("#form-login").submit(function(){
  var email = $("#form-login input[name='username']").val()
  var password = $("#form-login input[name='password']").val()

  firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
    // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
    // ...
  });
  firebase.auth().currentUser.getToken(/* forceRefresh */ true).then(function(idToken) {
    // Send token to your backend via HTTPS
    console.log(idToken)
    $.ajax({
      type: "POST",
      url: "/authenticate",
      data: {"idToken": idToken},
      dataType: "json",
      success: function(result){
        console.log(result)
      }
    });
    // ...
  }).catch(function(error) {
    // Handle error
  });
  return false
})
console.log(idToken) returns a string.

My server-side code:
app.post('/authenticate', function(req, res){
  var idToken = req.body.idToken
  console.log(idToken)

  firebase.auth().verifyIdToken(idToken).then(function(decodedToken) {
    var uid = decodedToken.uid;
    console.log(uid)
    // ...
  }).catch(function(error) {
    // Handle error
    console.log(error)
  });
})

This is the response I get:

POST /authenticate 500 5.289 ms - 1151
TypeError: firebase.auth(...).verifyIdToken is not a function

Don't really know where to look from here. I copied the docs exactly. Any ideas?

Much appreciated.

Bassam

unread,
Sep 13, 2016, 5:51:39 PM9/13/16
to Firebase Google Group
Hey Mark,
You are probably not instantiating an admin auth instance on your backend:
var firebase = require("firebase");

// Admin instance initialized with a service account.
var adminConfig = {
  serviceAccount: "serviceAccountCredentials.json"
}
var adminApp = firebase.initializeApp(adminConfig, 'admin');
adminApp.auth().verifyIdToken(idToken).then...

Jacob Wenger

unread,
Sep 19, 2016, 8:11:14 PM9/19/16
to fireba...@googlegroups.com
Bassam is exactly correct. You can read more details of how this work here.

Cheers,
Jacob

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/1bb8df36-9096-431c-b49a-fc5e92100f0e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages