Refresh Token In Flutter
I'm working on a finance project (Flutter) where the auth token gotten from the back-end expires frequently. How can I keep the token from expiring as long as the user is using the
Solution 1:
What I suggest is you can handle the things in simple manner like when fetching the data if the token expires you get a 401 unAuthorized Exception where you can ask for a new token(refresh Token) and then make the fetch request again. Let me know if it worked for you.
Solution 2:
Use oauth_dio: ^0.2.3 https://pub.dev/packages/oauth_dio
OAuthToken token = oauth.requestToken(
RefreshTokenGrant(
refreshToken: '<YOUR REFRESH TOKEN>'
)
).then((token) {
print(token.accessToken);
});
Post a Comment for "Refresh Token In Flutter"