3

I'm trying to have a laravel passport authentication, generating access tokens and storing them to localStorage, I'm able to get the access token but while placing it into localStorage I'm unable to fetch the value, while doing so I'm implementing something like this:

axios.post('/oauth/token', postData).then(response => {
    if(response.status === 200)
    {
        authUser.access_token = response.data.access_token;
        authUser.refresh_token = response.data.refresh_token;
        console.log(authUser);
        window.localStorage.setItem('authUser', JSON.stringify(authUser))
        console.log(window.localStorage.getItem('authUser'))
    }
})

As I said I'm implementing in predefined laravel so the resources I'm using is defaults. Do I need to add anything more? like vue-resource

Nitish Kumar
  • 6,054
  • 21
  • 82
  • 148

1 Answers1

3

Remember to parse the value, since you used JSON.strigify, the following should work:

// Saving
localStorage.setItem('authUser', JSON.stringify(authUser));

// Fetching
JSON.parse(localStorage.getItem('authUser'))
Nicklas Kevin Frank
  • 6,079
  • 4
  • 38
  • 63