You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: CHANGELOG.md
+7
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
7
7
## [Unreleased]
8
8
9
+
## [0.5.0] - 2024-06-06
10
+
11
+
### Changes
12
+
13
+
- Fixed the session refresh loop in all the request interceptors that occurred when an API returned a 401 response despite a valid session. Interceptors now attempt to refresh the session a maximum of ten times before throwing an error. The retry limit is configurable via the `maxRetryAttemptsForSessionRefresh` option.
if (responseCode == SuperTokens.config.sessionExpiredStatusCode) {
188
+
/**
189
+
* An API may return a 401 error response even with a valid session, causing a session refresh loop in the interceptor.
190
+
* To prevent this infinite loop, we break out of the loop after retrying the original request a specified number of times.
191
+
* The maximum number of retry attempts is defined by maxRetryAttemptsForSessionRefresh config variable.
192
+
*/
193
+
if (sessionRefreshAttempts >= SuperTokens.config.maxRetryAttemptsForSessionRefresh) {
194
+
StringerrorMsg = "Received a 401 response from " + url + ". Attempted to refresh the session and retry the request with the updated session tokens " + SuperTokens.config.maxRetryAttemptsForSessionRefresh + " times, but each attempt resulted in a 401 error. The maximum session refresh limit has been reached. Please investigate your API. To increase the session refresh attempts, update maxRetryAttemptsForSessionRefresh in the config.";
195
+
System.err.println(errorMsg);
196
+
thrownewIllegalAccessException(errorMsg);
197
+
}
198
+
187
199
// Network call threw UnauthorisedAccess, try to call the refresh token endpoint and retry original call
if (response.code() == SuperTokens.config.sessionExpiredStatusCode) {
138
+
/**
139
+
* An API may return a 401 error response even with a valid session, causing a session refresh loop in the interceptor.
140
+
* To prevent this infinite loop, we break out of the loop after retrying the original request a specified number of times.
141
+
* The maximum number of retry attempts is defined by maxRetryAttemptsForSessionRefresh config variable.
142
+
*/
143
+
if (sessionRefreshAttempts >= SuperTokens.config.maxRetryAttemptsForSessionRefresh) {
144
+
StringerrorMsg = "Received a 401 response from " + requestUrl + ". Attempted to refresh the session and retry the request with the updated session tokens " + SuperTokens.config.maxRetryAttemptsForSessionRefresh + " times, but each attempt resulted in a 401 error. The maximum session refresh limit has been reached. Please investigate your API. To increase the session refresh attempts, update maxRetryAttemptsForSessionRefresh in the config.";
145
+
System.err.println(errorMsg);
146
+
thrownewIOException(errorMsg);
147
+
}
148
+
137
149
// Cloning the response object, if retry is false then we return this
0 commit comments