DEV Community

Discussion on: Nuxt like a pro. Use service pattern (My Best practice)

Collapse
 
bacodekiller profile image
Quang Hiep • Edited

how to use it with Interceptors axios for refresh token when "token is invalid"? And save token, refresh token to cookies?

Collapse
 
radonirinamaminiaina profile image
Radonirina Maminiaina

You can use interceptor and in onResponse you can check if your token is valid or not.

Collapse
 
bacodekiller profile image
Quang Hiep

yes. when refresh token success but should I save token to vuex or cookies? thanks.

Thread Thread
 
radonirinamaminiaina profile image
Radonirina Maminiaina

The simplest way is using localstorage to save your token.

Thread Thread
 
bacodekiller profile image
Quang Hiep

But localStorage is client-side. How can i save it from server nuxtjs?

Thread Thread
 
radonirinamaminiaina profile image
Radonirina Maminiaina

You can use this lib and use cookie for saving the info within nuxt server

Thread Thread
 
bacodekiller profile image
Quang Hiep

can you give an example using lib or project using lib? tks you

Thread Thread
 
radonirinamaminiaina profile image
Radonirina Maminiaina

You can see this doc