refreshSessionToken static method
Implementation
static Future<String> refreshSessionToken(String refreshToken) async {
// if (hasTokenExpired(deviceToken)) {
// deviceToken = await refreshDeviceToken();
// }
Dio dio = Dio();
dio.options.headers['Content-Type'] = "application/x-www-form-urlencoded";
dio.options.headers["authorization"] = 'Bearer $refreshToken';
String url = "${AppUrls.baseUrlVSMS}/subscriberv2/v1/refreshtoken";
final Response response;
try {
response = await dio.get(url);
} catch (error) {
//this means the refresh token was revoked
return "";
}
var data = response.data;
String newSessionToken = data['success'];
String newRefreshToken = data['refreshtoken'];
SharedPreferences sharedPreferences = await DeviceStorage().getInstance();
await sharedPreferences.setString(
DeviceStorage.sessionToken, newSessionToken);
await sharedPreferences.setString(
DeviceStorage.refreshToken, newRefreshToken);
return newSessionToken;
}