isAuthenticated static method

Future<bool> isAuthenticated()

Implementation

static Future<bool> isAuthenticated() async {
  String accessToken = await getAccessToken();
  bool isAuthenticated = accessToken.isNotEmpty;
  if (kDebugMode) {
    print(isAuthenticated);
  }
  if (isAuthenticated) {
    try {
      HeraResponse response = await _heraClient.validateToken(HeraRequest(
          token: Token()..accessToken = accessToken,
          authToken: AuthToken(userToken: accessToken)));
      response = await _heraClient.get(HeraRequest(
        authToken: AuthToken(userToken: accessToken),
      ));
      _setCurrentUser(response.user);
    } catch (e) {
      if (kDebugMode) {
        print(e.toString());
      }
      isAuthenticated = false;
      _setAccessToken("");
      _setRefreshToken("");
    }
  }
  return isAuthenticated;
}