Sunday, 7 May 2017

Res.render in POST request (auth system) does not work, why?

The below is supposed to be an authentication system, but I face a problem. On a button click on the front-end, this is what happens:

firebaseAUTH.signInWithEmailAndPassword(email, password).then(function (user) {
    console.log('user has signed in with e-mail address: '+user.email+' and user ID: '+user.uid)
    firebaseAUTH.currentUser.getToken(true).then(function(idToken) {
    // Send token to your backend via HTTPS (JWT)
    $.ajax(
    {
      url: '/auth',
      type: 'POST',
      data: {token: idToken},
      success: function (response){
      }
})
}).catch(function(error) {
// Handle error
console.log(error.message)
})

And then with res.render I am trying to render a page, but it simply does not work. What am I missing here? Why does it not render at all (I do have a template file called like that, so it should work).

app.post('/auth', function(req,res,next){
  var token = req.body.token
  admin.auth().verifyIdToken(token)
    .then(function(decodedToken) {
      console.log(decodedToken.uid)
      res.render('index', {userID: uid})
    }).catch(function(error) {
      console.log(error.message)
    })
})



via huzal12

No comments:

Post a Comment