handleRefreshToken method
Implementation
Future<bool> handleRefreshToken() async {
final refreshToken = await _storage.read(key: 'refreshToken');
final accessTokenStore = await _storage.read(key: 'accessToken');
final response = await dio.post('$baseUrlRoot/api/m/v1/auths/refresh-token',
data: {'refreshToken': refreshToken, 'accessToken': accessTokenStore});
if (response.statusCode == 201) {
UserCurrent userCurrent = UserCurrent.fromJson(response.data);
accessToken = userCurrent.accessToken;
await _storage.write(key: 'accessToken', value: userCurrent.accessToken);
await _storage.write(
key: 'refreshToken', value: userCurrent.refreshToken);
return true;
} else {
// refresh token is wrong
accessToken = null;
_storage.deleteAll();
return false;
}
}