-
I am working on a Flutter project using the Nylo framework and am currently implementing user authentication. My backend API uses JWT for access tokens and also provides refresh tokens for maintaining user sessions. I would like to know the best practices for integrating both JWT and refresh token mechanisms within the Nylo framework.
Any guidance, code snippets, or references to relevant documentation would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @darezzed, Sorry for the late reply on this! If this were a requirement in one of my Nylo projects, I would first: Create a method that would refresh the token, e.g. send an API request and then replace the existing token in local storage. refreshToken() async {
dynamic newTokenResponse = await api<MyApiService>((request) => request.newToken());
// Save the token
await NyStorage.store('user_token', newTokenResponse.token);
} Then, create an Interceptor for Lastly, you'll need to implement a way to check when the token is expired in the In the next version of Nylo, I'll attempt to build a custom class that extends the base Interceptor class that can handle this, it could help a lot of people. |
Beta Was this translation helpful? Give feedback.
@darezzed,
In the latest version, I've added three new methods that you can override to make life easier for auth tokens.
The first is for setting authentication headers.
The second …