How to add values ​​to localstorage in vue

I'm trying to have laravel passport authentication

, generating access tokens

and by storing them in localStorage

, I can get the access token, but by putting it in localStorage, I cannot retrieve the value, while doing this I am 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 am implementing in a predefined laravel, so the resources I am using are the defaults. Do I need to add anything else? egvue-resource

+3


source to share


1 answer


Remember to parse the value, since you used the JSON.strigify

following should work:



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

// Fetching
JSON.parse(localStorage.getItem('authUser'))

      

+3


source







All Articles