Skip to content

Comments

fix loop in redirect#5

Merged
guilbill merged 1 commit intomainfrom
fix-login-loop
Jan 26, 2026
Merged

fix loop in redirect#5
guilbill merged 1 commit intomainfrom
fix-login-loop

Conversation

@Nitix
Copy link
Contributor

@Nitix Nitix commented Jan 26, 2026

The lib was looping between checkAuth and logout.

Copilot AI review requested due to automatic review settings January 26, 2026 10:24
@guilbill guilbill merged commit c836231 into main Jan 26, 2026
7 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a redirect loop issue between the checkAuth and logout methods in the APISIX OIDC auth provider by simplifying the redirect mechanism and removing the isRedirecting guard flag.

Changes:

  • Removed the isRedirecting flag and setTimeout delay mechanism from checkAuth and checkError methods
  • Changed logout to perform manual redirects via window.location.href instead of returning a redirect URL
  • Updated code formatting to use single quotes and 2-space indentation (via prettier configuration)
  • Bumped package version from 1.2.0 to 1.2.1

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
packages/ra-apisix-oidc/src/apisixOidcAuthProvider.ts Refactored auth flow to fix redirect loop by removing isRedirecting flag, simplifying redirects, and reformatting code
packages/ra-apisix-oidc/package.json Version bump to 1.2.1 and formatting updates
package-lock.json Version update (inconsistent with package.json)
.prettierrc.js Changed tab width from 4 to 2 spaces

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 42 to 50
logout: async () => {
const accessToken = storage.getItem("access_token");
const accessToken = storage.getItem('access_token');
if (!accessToken) {
return Promise.resolve();
return Promise.reject();
}
storage.removeItem("access_token");
return Promise.resolve(logoutURL);
storage.removeItem('access_token');
window.location.href = logoutURL;
return Promise.reject();
},
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logout method has changed its behavior: (1) It now rejects when no access token exists (previously resolved), and (2) It manually redirects via window.location.href and then rejects (previously returned the logout URL as a resolved value for react-admin to handle). While these changes may be part of fixing the reported loop issue, consider the implications: rejecting when already logged out may cause unnecessary error handling, and manual redirects with rejection prevent react-admin from cleaning up state. Verify through testing that this approach works correctly with react-admin's logout flow and doesn't cause unexpected error messages or UI states.

Copilot uses AI. Check for mistakes.
Comment on lines +51 to +65
checkError: error => {
if (error.status === 401) {
storage.removeItem("access_token");
if (!isRedirecting) {
isRedirecting = true;
saveCurrentLocation(storage);
setTimeout(() => {
window.location.href = loginURL;
}, 100);
}
return Promise.reject({ logoutUser: false });
storage.removeItem('access_token');
saveCurrentLocation(storage);
window.location.href = loginURL;
return Promise.reject();
}
return Promise.resolve();
},
checkAuth: async () => {
const accessToken = storage.getItem("access_token");
const accessToken = storage.getItem('access_token');
if (!accessToken) {
if (!isRedirecting) {
isRedirecting = true;
saveCurrentLocation(storage);
setTimeout(() => {
window.location.href = loginURL;
}, 100);
}
return Promise.reject({ redirectTo: false });
saveCurrentLocation(storage);
window.location.href = loginURL;
return Promise.reject();
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both checkAuth and checkError now perform synchronous redirects via window.location.href and return Promise.reject() without parameters. The previous implementation used special rejection parameters like { redirectTo: false } and { logoutUser: false } to control react-admin's redirect behavior, and included an isRedirecting flag to prevent concurrent redirects. While removing these mechanisms may fix the reported loop issue, verify through testing that: (1) react-admin doesn't attempt its own redirects after the manual window.location.href assignment, (2) multiple simultaneous failures don't cause multiple redirect attempts, and (3) the user experience is smooth without the 100ms setTimeout delay that was previously used.

Copilot uses AI. Check for mistakes.
semi: true,
singleQuote: true,
tabWidth: 4,
tabWidth: 2,
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the tabWidth from 4 to 2 is a project-wide formatting change that will affect all files when they are reformatted. This appears to be applied to the apisixOidcAuthProvider.ts file in this PR, but it's a broader configuration change. Consider whether this formatting change should be applied consistently across the entire codebase in a separate PR to avoid mixing formatting changes with functional changes, or ensure all files have been reformatted consistently.

Suggested change
tabWidth: 2,
tabWidth: 4,

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants