Add a title to window.location.pathname

I am setting up authentication for the application. After I make a mail request for logging in, a JSON web token is sent in response. I can connect it to the header through Ajax. The problem is that when using window.location.pathname to redirect after login, since it is not an Ajax request, it does not have a token attached to the header. How do I get around this?

$.ajaxSetup({ headers: { 'x-access-token': window.localStorage.jwt } }); var Auth = { signup: function () { console.log('signuppp'); var userSignup = { username: $('#usernameSignup').val(), password: $('#passwordSignup').val() }; console.log(userSignup) return $.post('/api/users/register', userSignup, function (resp) { console.log('resp: ',resp); window.localStorage.setItem('jwt', resp.token); //does not have x-access-token header window.location.pathname = '/'; }) }, 
+6
source share
1 answer

Short answer: you cannot set HTTP headers using window.location .

Adding http headers to window.location.href in an Angular app

+2
source

All Articles