getAppToken method

Future<String> getAppToken(
  1. {bool renew = false}
)

Implementation

Future<String> getAppToken({bool renew = false}) async {
  final storedAppToken = await prefs.getAppToken();
  final isAppTokenExpired = await prefs.isAppTokenExpired();
  final notEmptyAppToken = storedAppToken != null && storedAppToken != "";

  if (!renew && notEmptyAppToken && !isAppTokenExpired) {
    return storedAppToken;
  } else {
    return _retrieveToken(grantTypeApp, {}).then((credential) async {
      await prefs.resetAppToken();
      await prefs.setAppToken(credential.accessToken);
      await prefs.setAppRefreshToken(credential.refreshToken);
      await prefs.setAppTokenExpiration(credential.expires);
      return credential.accessToken;
    });
  }
}