Skip to content

Commit

Permalink
Reject promise in checkError with logoutUser: false and without redir…
Browse files Browse the repository at this point in the history
…ectTo causes an error marmelab#10172
  • Loading branch information
rktamil committed Sep 1, 2024
1 parent 733e7a6 commit 05dc2a6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/ra-core/src/auth/useLogoutIfAccessDenied.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,17 @@ const useLogoutIfAccessDenied = (): LogoutIfAccessDenied => {
if (logoutUser) {
logout({}, redirectTo);
} else {
if (redirectTo.startsWith('http')) {
// absolute link (e.g. https://my.oidc.server/login)
window.location.href = redirectTo;
if (redirectTo != null) {

This comment has been minimized.

Copy link
@Ritzrawal

Ritzrawal Dec 22, 2024

I think it would be better instead of using this nested if else condition we can make functions and use for the clean code e.g:

`onst handleRedirect = (url) => {
if (url.startsWith('http')) {
window.location.href = url; // Redirect to external URL
} else {
navigate(url); // Navigate to internal route
}
};

if (logoutUser) {
    // Perform the logout operation
    logout({}, redirectTo);
} else if (redirectTo) {
    handleRedirect(redirectTo);
} else {
    // No redirect specified; log and return false
    console.error('Logout unsuccessful: No redirect URL provided.');
    return false;
}

};`

if (redirectTo.startsWith('http')) {
// absolute link (e.g. https://my.oidc.server/login)
window.location.href = redirectTo;
} else {
// internal location
navigate(redirectTo);
}
} else {
// internal location
navigate(redirectTo);
// If there is not redirect return false saying loguout is not successful
return false;
}
}

Expand Down

0 comments on commit 05dc2a6

Please sign in to comment.