Skip to content

Commit

Permalink
fix: refresh loop in axios interceptor (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus authored May 24, 2024
1 parent a0570a9 commit 581a2cd
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [5.0.1] - 2024-05-24

### Fixes

- Fix a possible refresh loop in the axios interceptor

## [5.0.0] - 2024-05-08

### Breaking changes
Expand Down
3 changes: 2 additions & 1 deletion lib/build/axios.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/ts/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ async function setAuthorizationHeaderIfRequired(requestConfig: AxiosRequestConfi
...requestConfig.headers,
Authorization: `Bearer ${accessToken}`
};
(requestConfig as any).__supertokensAddedAuthHeader = true;
}
} else {
logDebugMessage("setAuthorizationHeaderIfRequired: token for header based auth not found");
Expand All @@ -510,7 +511,7 @@ async function removeAuthHeaderIfMatchesLocalToken(config: AxiosRequestConfig) {
const authHeader = config.headers!.Authorization || config.headers!.authorization;

if (accessToken !== undefined && refreshToken !== undefined) {
if (authHeader === `Bearer ${accessToken}`) {
if (authHeader === `Bearer ${accessToken}` || "__supertokensAddedAuthHeader" in config) {
// We are ignoring the Authorization header set by the user in this case, because it would cause issues
// If we do not ignore this, then this header would be used even if the request is being retried after a refresh, even though it contains an outdated access token.
// This causes an infinite refresh loop.
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
export const package_version = "5.0.0";
export const package_version = "5.0.1";

export const supported_fdi = ["1.16", "1.17", "1.18", "1.19"];
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supertokens-react-native",
"version": "5.0.0",
"version": "5.0.1",
"description": "React Native SDK for SuperTokens",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 581a2cd

Please sign in to comment.