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

1 Answer 1

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'))
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, it works, but when I inspect the application in chrome, I'm unable to view in my application local storage, is it hidden?
Yes the same place, i'm unable to view any values
Sorry, if the linked post didn't help then I can't assist you any further.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.