Kasheftin / nuxt-auth-from-scratch

48 stars 19 forks source link

token is lost after refresh #3

Closed WeyIin closed 6 years ago

WeyIin commented 6 years ago

Since my back end expects Authorization Bearer token, I changed x-access-token to Authorization. Everything works fine but on refresh, token is lost and it logs me out.

What am I missing?

Help, please! :)

Kasheftin commented 6 years ago

Hi, have you used the search for 'x-access-token' among the source files of the project? I see 8 results in the frontend folder. I suppose they should be replaced to Authorization in your case. Does the 'Authorization' cookie exist after you log in?

WeyIin commented 6 years ago

Hey @Kasheftin :wave: Yeah, I used search for 'x-access-token' and none pop out, and if I search for Authorization, there are 8 results.

Yes, Authorization cookie exists when I log in, and even after refresh, that cookie remains set in my browser.

Since the cookie has to have 'Bearer ' - the actual cookie value is 'Bearer%20eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjEsImlhdCI6MTUyMjM1NDM4OX0.N7TNiirpfDJAY6lzOua-lELEFbdHtxHCpfpmgK9IREM'

Can you notice %20 - space code instead of an actual space. You think that might be causing issues?

WeyIin commented 6 years ago

I had it like this:

utils/auth.js axios.defaults.headers.common['Authorization'] = 'Bearer ' + token

store/auth.js setAuthToken(response.data.token)

It didn't work but changing to:

utils/auth.js axios.defaults.headers.common['Authorization'] = token

store/auth.js setAuthToken('Bearer ' + response.data.token)

works! Weird but okay ^_^

Anyway, this issue is now solved and hopefully it is going to be helpful to other people being stuck at the same issue I've had.

Edit: %20 character instead of space does not change the behaviour, authorization works regardless, although it does NOT work in postman.