0

I got an application where a specific function makes a post request and receives in the callback a JsonWebToken. I have to redirect to another endpoint which will render a new page, passing the token in the header.

Using the following code, I know it gets on the desired endpoint, because "Here I am" is printed, but the page is not rendered. What am I doing wrong?

Controller:

var app = angular.module('loginApp'['ui.utils.masks','ui.bootstrap']) 
app.controller('LoginCtrl', function($location,$scope,$http){


function login(){
$http.post('/authentication',$scope.user).then(function 
successCallback(response) {

      $http({
             url : '/home',
             method : 'GET',
             headers : {
                   Authorization: "JWT " + response.data.token
             }
         })
     }
}

Routes file:

var express = require('express')
var router = express.Router()

router.get('/home', function(req, res) {
    console.log("Passing here")
    res.render('home.pug')
}

module.exports = router
Community
  • 1
  • 1
Daniel
  • 1

1 Answers1

0

You are making a GET request which successfully authenticates (because of your JWT) but you are never actually redirecting the user to a new page.

You could use window.location on the frontend or handle the direct on the backend.

Here is a related question on going to a new page with a custom Authorization header.

justin
  • 439
  • 2
  • 10