saveTokensFromHeaders method

Future<void> saveTokensFromHeaders(
  1. dynamic response
)

Implementation

Future<void> saveTokensFromHeaders(Response response) async {
  String? frontTokenFromResponse =
      response.headers.map[frontTokenHeaderKey]?.first.toString();

  if (frontTokenFromResponse != null) {
    await FrontToken.setItem(frontTokenFromResponse);
  }

  String? antiCSRFFromResponse =
      response.headers.map[antiCSRFHeaderKey]?.first.toString();

  if (antiCSRFFromResponse != null) {
    LocalSessionState localSessionState =
        await SuperTokensUtils.getLocalSessionState();

    await AntiCSRF.setToken(
      antiCSRFFromResponse,
      localSessionState.lastAccessTokenUpdate,
    );
  }

  String? accessHeader =
      response.headers.map[ACCESS_TOKEN_NAME]?.first.toString();

  if (accessHeader != null) {
    await Utils.setToken(TokenType.ACCESS, accessHeader);
  }
  String? refreshHeader =
      response.headers.map[REFRESH_TOKEN_NAME]?.first.toString();

  if (refreshHeader != null) {
    await Utils.setToken(TokenType.REFRESH, refreshHeader);
  }
}