refreshToken method

Future refreshToken(
  1. Future callback()
)

Implementation

Future<dynamic> refreshToken(Future<dynamic> Function() callback) async {
  try{
    var module = await SharedPrefs.getModule();
    module = module.isEmpty ? globalModule : module;
    var body = RefreshTokenBodyModel(refreshToken: await SharedPrefs.getRefreshToken(), phoneOs: await SharedPrefs.getDeviceOS(), phoneBrand: await SharedPrefs.getDeviceBrand(), deviceId: await SharedPrefs.getDeviceId(), phoneModel: await SharedPrefs.getDeviceModel());
    Response response = await _dio.post(refreshTokenURL, data: body.toJson(), options: Options(headers: {'module': module},));
    var userInfoResponseModel = UserInfoResponseModel.fromJson(response.data);
    if(userInfoResponseModel.issuccess ?? false){
      await SharedPrefs.saveTokens(accessToken: userInfoResponseModel.payload?.accessToken ?? "", refreshToken: userInfoResponseModel.payload?.refreshToken ?? "");
      return await callback();
    }
  }catch(e){
    DioExceptions.fromDioError(dioError: e as DioException).toString();
    var response = e.response?.data;
    debugPrint("Plugin refreshToken-> ${response == null ? e.message : response.toString()}");
  }
}