Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refresh loop in axios interceptor #123

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading