0

I'm new to NativeScript and not that experienced with Vue so I'm having troubles working with tokens. I'm using Magento API, I can do the login and save the token locally, but I'm doing this at the login page itself, I don't know if it's the right way, maybe a service would be better but can't pull off that right too.
I need to do an interceptor so I can refresh the token or logout the user when the token is no longer valid. But I can't seem to find a tutorial way to do this and one I can understand right what I'm doing.
Anyone can explain how this works and how to do it or have found a understandable tutorial for someone inexperienced?

Many thanks in advance.

Best regards, Rui Silva

Rui Silva
  • 103
  • 3
  • You could use Axios like described here, [Axios Interceptor](https://stackoverflow.com/questions/52737078/how-can-you-use-axios-interceptors) – Robertino Vasilescu Sep 24 '20 at 07:41
  • Thanks, I looked a bit but I always get lost how to do this. I need an example to understand, so I have a folder called share, and there I have a userData.js that as the functions to get user information by http.request. Now I need an interceptor that runs everytime any http request runs and check If the token is valid. Where do I do this function? Inside the same userData.js? Do I need to create it somewhere else and import it? I can't manage do get this working :/ – Rui Silva Sep 24 '20 at 08:51
  • With that link I suggested you pass from http to Axios but if you want to use http then this will help, https://github.com/mswjs/node-request-interceptor#readme. There are example how to use it there. You need to apply those examples in your userData.js – Robertino Vasilescu Sep 25 '20 at 10:54

0 Answers0