signOut method

Future<void> signOut()

Implementation

Future<void> signOut() async {
  // Throw error is authentication status not found
  final idToken = await _tokenStorage.idToken;

  final httpClient = _httpClient ?? http.Client();

  if (idToken == null) {
    throw LogtoAuthException(
        LogtoAuthExceptions.authenticationError, 'not authenticated');
  }

  try {
    final oidcConfig = await _getOidcConfig(httpClient);

    // Revoke refresh token if exist
    final refreshToken = await _tokenStorage.refreshToken;

    if (refreshToken != null) {
      try {
        await logto_core.revoke(
          httpClient: httpClient,
          revocationEndpoint: oidcConfig.revocationEndpoint,
          clientId: config.appId,
          token: refreshToken,
        );
      } catch (e) {
        // Do Nothing silently revoke the token
      }
    }

    await _tokenStorage.clear();
  } finally {
    if (_httpClient == null) {
      httpClient.close();
    }
  }
}