Cannot grab access token through Vue

Hello,

I’m building a Vue application and trying to use the ‘Vue.prototype.$auth.getAccessToken()’ method to grab my token value to pass to my API (using axios in a JavaScript file).

Seems like it only grabs my token about 50% of the time even though I see the token in my local storage. Seems to not grab it as frequently if I put the url into the address bar manually rather than doing it through Vue Router.

Has anybody else experience this / know the best way to go about grabbing the token? Should I pull it right from storage?

Thank you!

Hey there. Are you running $auth.getAccessToken() in the created() method of your component? If not, try that. If you are still having issues, can you post your router settings?

Hi Cale,

We are using this in a service layer (meaning, an external JS file called by components).
I was able to pull it within that Javascript file by brute-forcing it with:

return JSON.parse(localStorage.getItem('okta-token-storage')).accessToken.accessToken;

1 Like