saveTokensFromHeaders method
Future<void>
saveTokensFromHeaders(
)
Implementation
Future<void> saveTokensFromHeaders(Response response) async {
logDebugMessage('SuperTokensInterceptorWrapper.saveTokensFromHeaders: Saving tokens from header');
String? frontTokenFromResponse =
response.headers.map[frontTokenHeaderKey]?.first.toString();
logDebugMessage('SuperTokensInterceptorWrapper.saveTokensFromHeaders: frontTokenFromResponse: ${frontTokenFromResponse}');
if (frontTokenFromResponse != null) {
logDebugMessage('SuperTokensInterceptorWrapper.saveTokensFromHeaders: Setting token since it is not null');
await FrontToken.setItem(frontTokenFromResponse);
}
String? antiCSRFFromResponse =
response.headers.map[antiCSRFHeaderKey]?.first.toString();
if (antiCSRFFromResponse != null) {
LocalSessionState localSessionState =
await SuperTokensUtils.getLocalSessionState();
logDebugMessage('SuperTokensInterceptorWrapper.saveTokensFromHeaders: Setting token in AntiCSRF');
await AntiCSRF.setToken(
antiCSRFFromResponse,
localSessionState.lastAccessTokenUpdate,
);
}
String? accessHeader =
response.headers.map[ACCESS_TOKEN_NAME]?.first.toString();
logDebugMessage('SuperTokensInterceptorWrapper.saveTokensFromHeaders: accessHeader: ${accessHeader}');
if (accessHeader != null) {
logDebugMessage('SuperTokensInterceptorWrapper.saveTokensFromHeaders: Setting access header');
await Utils.setToken(TokenType.ACCESS, accessHeader);
}
String? refreshHeader =
response.headers.map[REFRESH_TOKEN_NAME]?.first.toString();
logDebugMessage('SuperTokensInterceptorWrapper.saveTokensFromHeaders: refreshHeader: ${refreshHeader}');
if (refreshHeader != null) {
logDebugMessage('SuperTokensInterceptorWrapper.saveTokensFromHeaders: Setting refresh header');
await Utils.setToken(TokenType.REFRESH, refreshHeader);
}
}