supertokens-website
Advanced tools
Comparing version 20.1.3 to 20.1.4
@@ -10,2 +10,9 @@ # Changelog | ||
## [20.1.4] - 2024-07-11 | ||
### Changes | ||
- Removed redundant `removeToken` calls | ||
- Improves test stability | ||
## [20.1.3] - 2024-07-09 | ||
@@ -12,0 +19,0 @@ |
@@ -286,10 +286,7 @@ "use strict"; | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var doNotDoInterception, url, preRequestLSS, config, _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
var doNotDoInterception, url, preRequestLSS, config; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
doNotDoInterception = false; | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, , 8, 14]); | ||
if (!fetch_1.default.initCalled) { | ||
@@ -341,11 +338,11 @@ throw new Error("init function not called"); | ||
return [4 /*yield*/, (0, fetch_1.getLocalSessionState)(false)]; | ||
case 1: | ||
preRequestLSS = _a.sent(); | ||
return [4 /*yield*/, saveTokensFromHeaders(response)]; | ||
case 2: | ||
preRequestLSS = _b.sent(); | ||
return [4 /*yield*/, saveTokensFromHeaders(response)]; | ||
case 3: | ||
_b.sent(); | ||
_a.sent(); | ||
(0, | ||
fetch_1.fireSessionUpdateEventsIfNecessary)(preRequestLSS.status === "EXISTS", response.status, response.headers["front-token"]); | ||
if (!(response.status === fetch_1.default.config.sessionExpiredStatusCode)) | ||
return [3 /*break*/, 4]; | ||
return [3 /*break*/, 3]; | ||
(0, logger_1.logDebugMessage)("responseInterceptor: Status code is: " + response.status); | ||
@@ -369,40 +366,13 @@ config = response.config; | ||
]; | ||
case 4: | ||
case 3: | ||
if (!(response.status === fetch_1.default.config.invalidClaimStatusCode)) | ||
return [3 /*break*/, 6]; | ||
return [3 /*break*/, 5]; | ||
// only fire event if body is defined. | ||
return [4 /*yield*/, (0, fetch_1.onInvalidClaimResponse)(response)]; | ||
case 4: | ||
// only fire event if body is defined. | ||
_a.sent(); | ||
_a.label = 5; | ||
case 5: | ||
// only fire event if body is defined. | ||
_b.sent(); | ||
_b.label = 6; | ||
case 6: | ||
return [2 /*return*/, response]; | ||
case 7: | ||
return [3 /*break*/, 14]; | ||
case 8: | ||
_a = !doNotDoInterception; | ||
if (!_a) return [3 /*break*/, 10]; | ||
return [4 /*yield*/, (0, fetch_1.getLocalSessionState)(false)]; | ||
case 9: | ||
// we do not call doesSessionExist here cause the user might override that | ||
// function here and then it may break the logic of our original implementation. | ||
// Calling getLocalSessionState with tryRefresh: false, since the session would have been refreshed in the try block if expired. | ||
_a = _b.sent().status === "NOT_EXISTS"; | ||
_b.label = 10; | ||
case 10: | ||
if (!_a) return [3 /*break*/, 13]; | ||
(0, | ||
logger_1.logDebugMessage)("responseInterceptor: local session doesn't exist, so removing anti-csrf and sFrontToken"); | ||
return [4 /*yield*/, fetch_1.AntiCsrfToken.removeToken()]; | ||
case 11: | ||
_b.sent(); | ||
return [4 /*yield*/, fetch_1.FrontToken.removeToken()]; | ||
case 12: | ||
_b.sent(); | ||
_b.label = 13; | ||
case 13: | ||
return [7 /*endfinally*/]; | ||
case 14: | ||
return [2 /*return*/]; | ||
} | ||
@@ -507,4 +477,3 @@ }); | ||
refreshResult, | ||
_c, | ||
postRequestIdToken; | ||
_c; | ||
return __generator(_a, function (_d) { | ||
@@ -562,16 +531,13 @@ switch (_d.label) { | ||
config = _d.sent(); | ||
returnObj = undefined; | ||
_d.label = 4; | ||
case 4: | ||
_d.trys.push([4, , 30, 35]); | ||
returnObj = undefined; | ||
_d.label = 5; | ||
if (!true) return [3 /*break*/, 28]; | ||
return [4 /*yield*/, (0, fetch_1.getLocalSessionState)(true)]; | ||
case 5: | ||
if (!true) return [3 /*break*/, 29]; | ||
return [4 /*yield*/, (0, fetch_1.getLocalSessionState)(true)]; | ||
case 6: | ||
preRequestLSS = _d.sent(); | ||
configWithAntiCsrf = config; | ||
if (!(preRequestLSS.status === "EXISTS")) return [3 /*break*/, 8]; | ||
if (!(preRequestLSS.status === "EXISTS")) return [3 /*break*/, 7]; | ||
return [4 /*yield*/, fetch_1.AntiCsrfToken.getToken(preRequestLSS.lastAccessTokenUpdate)]; | ||
case 7: | ||
case 6: | ||
antiCsrfToken = _d.sent(); | ||
@@ -591,4 +557,4 @@ if (antiCsrfToken !== undefined) { | ||
} | ||
_d.label = 8; | ||
case 8: | ||
_d.label = 7; | ||
case 7: | ||
if ( | ||
@@ -616,7 +582,7 @@ fetch_1.default.config.autoAddCredentials && | ||
return [4 /*yield*/, setAuthorizationHeaderIfRequired(configWithAntiCsrf)]; | ||
case 8: | ||
_d.sent(); | ||
_d.label = 9; | ||
case 9: | ||
_d.sent(); | ||
_d.label = 10; | ||
case 10: | ||
_d.trys.push([10, 15, , 28]); | ||
_d.trys.push([9, 14, , 27]); | ||
localPrevError = prevError; | ||
@@ -639,11 +605,11 @@ localPrevResponse = prevResponse; | ||
} | ||
if (!(localPrevResponse === undefined)) return [3 /*break*/, 12]; | ||
if (!(localPrevResponse === undefined)) return [3 /*break*/, 11]; | ||
return [4 /*yield*/, httpCall(configWithAntiCsrf)]; | ||
case 10: | ||
_b = _d.sent(); | ||
return [3 /*break*/, 12]; | ||
case 11: | ||
_b = _d.sent(); | ||
return [3 /*break*/, 13]; | ||
_b = localPrevResponse; | ||
_d.label = 12; | ||
case 12: | ||
_b = localPrevResponse; | ||
_d.label = 13; | ||
case 13: | ||
response = _b; | ||
@@ -655,3 +621,3 @@ // NOTE: No need to check for unauthorized response status here for session refresh, | ||
return [4 /*yield*/, saveTokensFromHeaders(response)]; | ||
case 14: | ||
case 13: | ||
_d.sent(); | ||
@@ -661,8 +627,8 @@ (0, | ||
return [2 /*return*/, response]; | ||
case 15: | ||
case 14: | ||
err_1 = _d.sent(); | ||
response = err_1.response; | ||
if (!(response !== undefined)) return [3 /*break*/, 26]; | ||
if (!(response !== undefined)) return [3 /*break*/, 25]; | ||
return [4 /*yield*/, saveTokensFromHeaders(response)]; | ||
case 16: | ||
case 15: | ||
_d.sent(); | ||
@@ -672,3 +638,3 @@ (0, | ||
if (!(response.status === fetch_1.default.config.sessionExpiredStatusCode)) | ||
return [3 /*break*/, 22]; | ||
return [3 /*break*/, 21]; | ||
(0, logger_1.logDebugMessage)("doRequest: Status code is: " + response.status); | ||
@@ -702,3 +668,3 @@ /** | ||
return [4 /*yield*/, (0, fetch_1.onUnauthorisedResponse)(preRequestLSS)]; | ||
case 17: | ||
case 16: | ||
refreshResult = _d.sent(); | ||
@@ -709,59 +675,41 @@ incrementSessionRefreshAttemptCount(config); | ||
console.log("!!!!", JSON.stringify(refreshResult)); | ||
if (!(refreshResult.result !== "RETRY")) return [3 /*break*/, 21]; | ||
if (!(refreshResult.result !== "RETRY")) return [3 /*break*/, 20]; | ||
(0, logger_1.logDebugMessage)("doRequest: Not retrying original request"); | ||
if (!(refreshResult.error !== undefined)) return [3 /*break*/, 19]; | ||
if (!(refreshResult.error !== undefined)) return [3 /*break*/, 18]; | ||
return [4 /*yield*/, (0, axiosError_1.createAxiosErrorFromFetchResp)(refreshResult.error)]; | ||
case 17: | ||
_c = _d.sent(); | ||
return [3 /*break*/, 19]; | ||
case 18: | ||
_c = _d.sent(); | ||
return [3 /*break*/, 20]; | ||
_c = err_1; | ||
_d.label = 19; | ||
case 19: | ||
_c = err_1; | ||
_d.label = 20; | ||
case 20: | ||
// Returning refreshResult.error as an Axios Error if we attempted a refresh | ||
// Returning the original error if we did not attempt refreshing | ||
returnObj = _c; | ||
return [3 /*break*/, 29]; | ||
return [3 /*break*/, 28]; | ||
case 20: | ||
(0, logger_1.logDebugMessage)("doRequest: Retrying original request"); | ||
return [3 /*break*/, 24]; | ||
case 21: | ||
(0, logger_1.logDebugMessage)("doRequest: Retrying original request"); | ||
return [3 /*break*/, 25]; | ||
case 22: | ||
if (!(response.status === fetch_1.default.config.invalidClaimStatusCode)) | ||
return [3 /*break*/, 24]; | ||
return [3 /*break*/, 23]; | ||
return [4 /*yield*/, (0, fetch_1.onInvalidClaimResponse)(response)]; | ||
case 22: | ||
_d.sent(); | ||
_d.label = 23; | ||
case 23: | ||
_d.sent(); | ||
_d.label = 24; | ||
throw err_1; | ||
case 24: | ||
return [3 /*break*/, 26]; | ||
case 25: | ||
throw err_1; | ||
case 25: | ||
case 26: | ||
return [3 /*break*/, 27]; | ||
case 26: | ||
throw err_1; | ||
case 27: | ||
return [3 /*break*/, 28]; | ||
return [3 /*break*/, 4]; | ||
case 28: | ||
return [3 /*break*/, 5]; | ||
case 29: | ||
// if it comes here, means we called break. which happens only if we have logged out. | ||
// which means it's a 401, so we throw | ||
throw returnObj; | ||
case 30: | ||
return [4 /*yield*/, (0, fetch_1.getLocalSessionState)(false)]; | ||
case 31: | ||
postRequestIdToken = _d.sent(); | ||
if (!(postRequestIdToken.status === "NOT_EXISTS")) return [3 /*break*/, 34]; | ||
(0, | ||
logger_1.logDebugMessage)("doRequest: local session doesn't exist, so removing anti-csrf and sFrontToken"); | ||
return [4 /*yield*/, fetch_1.AntiCsrfToken.removeToken()]; | ||
case 32: | ||
_d.sent(); | ||
return [4 /*yield*/, fetch_1.FrontToken.removeToken()]; | ||
case 33: | ||
_d.sent(); | ||
_d.label = 34; | ||
case 34: | ||
return [7 /*endfinally*/]; | ||
case 35: | ||
return [2 /*return*/]; | ||
} | ||
@@ -768,0 +716,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
export declare const package_version = "20.1.3"; | ||
export declare const package_version = "20.1.4"; | ||
export declare const supported_fdi: string[]; |
@@ -18,3 +18,3 @@ "use strict"; | ||
*/ | ||
exports.package_version = "20.1.3"; | ||
exports.package_version = "20.1.4"; | ||
exports.supported_fdi = ["1.16", "1.17", "1.18", "1.19", "2.0", "3.0"]; |
@@ -319,6 +319,3 @@ "use strict"; | ||
case 1: | ||
_a.trys.push([1, 14, , 18]); | ||
_a.label = 2; | ||
case 2: | ||
_a.trys.push([2, , 8, 13]); | ||
_a.trys.push([1, 7, , 11]); | ||
(0, logger_1.logDebugMessage)("XHRInterceptor.handleResponse: Interception started"); | ||
@@ -331,3 +328,3 @@ processState_1.ProcessState.getInstance().addState( | ||
return [4 /*yield*/, saveTokensFromHeaders(headers)]; | ||
case 3: | ||
case 2: | ||
_a.sent(); | ||
@@ -337,39 +334,21 @@ (0, | ||
if (!(status_1 === fetch_1.default.config.sessionExpiredStatusCode)) | ||
return [3 /*break*/, 5]; | ||
return [3 /*break*/, 4]; | ||
(0, logger_1.logDebugMessage)("responseInterceptor: Status code is: " + status_1); | ||
return [4 /*yield*/, handleRetryPostRefreshing()]; | ||
case 3: | ||
return [2 /*return*/, _a.sent()]; | ||
case 4: | ||
return [2 /*return*/, _a.sent()]; | ||
if (!(status_1 === fetch_1.default.config.invalidClaimStatusCode)) return [3 /*break*/, 6]; | ||
return [4 /*yield*/, (0, fetch_1.onInvalidClaimResponse)({ data: xhr.responseText })]; | ||
case 5: | ||
if (!(status_1 === fetch_1.default.config.invalidClaimStatusCode)) return [3 /*break*/, 7]; | ||
return [4 /*yield*/, (0, fetch_1.onInvalidClaimResponse)({ data: xhr.responseText })]; | ||
_a.sent(); | ||
_a.label = 6; | ||
case 6: | ||
_a.sent(); | ||
_a.label = 7; | ||
return [2 /*return*/, true]; | ||
case 7: | ||
return [2 /*return*/, true]; | ||
case 8: | ||
(0, logger_1.logDebugMessage)("XHRInterceptor.handleResponse: doFinallyCheck running"); | ||
return [4 /*yield*/, (0, fetch_1.getLocalSessionState)(false)]; | ||
case 9: | ||
if (!(_a.sent().status === "NOT_EXISTS")) return [3 /*break*/, 12]; | ||
(0, | ||
logger_1.logDebugMessage)("XHRInterceptor.handleResponse: local session doesn't exist, so removing anti-csrf and sFrontToken"); | ||
return [4 /*yield*/, fetch_1.AntiCsrfToken.removeToken()]; | ||
case 10: | ||
_a.sent(); | ||
return [4 /*yield*/, fetch_1.FrontToken.removeToken()]; | ||
case 11: | ||
_a.sent(); | ||
_a.label = 12; | ||
case 12: | ||
return [7 /*endfinally*/]; | ||
case 13: | ||
return [3 /*break*/, 18]; | ||
case 14: | ||
err_1 = _a.sent(); | ||
(0, logger_1.logDebugMessage)("XHRInterceptor.handleResponse: caught error"); | ||
if (!(err_1.status !== undefined)) return [3 /*break*/, 16]; | ||
if (!(err_1.status !== undefined)) return [3 /*break*/, 9]; | ||
return [4 /*yield*/, getXMLHttpStatusAndResponseTextFromFetchResponse(err_1)]; | ||
case 15: | ||
case 8: | ||
resp = _a.sent(); | ||
@@ -390,4 +369,4 @@ customGetterValues["status"] = resp.status; | ||
customGetterValues["responseText"] = resp.responseText; | ||
return [3 /*break*/, 17]; | ||
case 16: | ||
return [3 /*break*/, 10]; | ||
case 9: | ||
ev = new ProgressEvent("error"); | ||
@@ -399,6 +378,6 @@ ev.error = err_1; | ||
redispatchEvent("error", ev); | ||
_a.label = 17; | ||
case 17: | ||
_a.label = 10; | ||
case 10: | ||
return [2 /*return*/, true]; | ||
case 18: | ||
case 11: | ||
return [2 /*return*/]; | ||
@@ -405,0 +384,0 @@ } |
{ | ||
"name": "supertokens-website", | ||
"version": "20.1.3", | ||
"version": "20.1.4", | ||
"description": "frontend sdk for website to be used for auth solution.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
411339
7928