-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Enhancement
Copy link
Labels
Description
What you were expecting:
I would like to notify user when getPermissions
request is failing. To do it, I catch the error in checkError
and I reject promise with logoutUser: false
and without redirectTo
as I just want to display a notification without logout or redirect the user
What happened instead:
The notification is correctly displayed but I have a JS error:
TypeError: can't access property "startsWith", redirectTo is undefined
This comes from useLogoutIfAccessDenied
:
react-admin/packages/ra-core/src/auth/useLogoutIfAccessDenied.ts
Lines 103 to 113 in 75a6683
if (logoutUser) { | |
logout({}, redirectTo); | |
} else { | |
if (redirectTo.startsWith('http')) { | |
// absolute link (e.g. https://my.oidc.server/login) | |
window.location.href = redirectTo; | |
} else { | |
// internal location | |
navigate(redirectTo); | |
} | |
} |
Steps to reproduce:
Update getPermissions
and checkError
with following code:
getPermissions: () => {
return Promise.reject('getPermissions error');
},
checkError: (error) => {
if (error.status === 401 || error.status === 403) {
return Promise.reject({ message: 'Unauthorized' });
}
if (error === 'getPermissions error') {
return Promise.reject({
message: error,
logoutUser: false,
});
}
return Promise.resolve();
},
Environment
- React-admin version: 4.16.17
- React version: 18.2.0
- Stack trace (in case of a JS error):
logoutIfAccessDenied useLogoutIfAccessDenied.ts:105
step chunk-6GJJR47V.js:4115
verb chunk-6GJJR47V.js:4062
__awaiter2 chunk-6GJJR47V.js:4048
__awaiter2 chunk-6GJJR47V.js:4030
logoutIfAccessDenied useLogoutIfAccessDenied.ts:51
promise callback*useLogoutIfAccessDenied/logoutIfAccessDenied< useLogoutIfAccessDenied.ts:51
onError usePermissions.ts:57
NotifyManager notifyManager.js:62
notifyFn notifyManager.js:10
flush notifyManager.js:77
flush notifyManager.js:76
batchedUpdates$1 React
flush notifyManager.js:75
promise callback*scheduleMicrotask utils.js:322
flush notifyManager.js:74
batch notifyManager.js:30
dispatch query.js:392
onError query.js:348
reject2 retryer.js:67
run2 retryer.js:132
promise callback*run2 retryer.js:116
run2 retryer.js:149
promise callback*Retryer2/run2/< retryer.js:145
promise callback*run2 retryer.js:116
run2 retryer.js:149
promise callback*Retryer2/run2/< retryer.js:145
promise callback*run2 retryer.js:116
run2 retryer.js:149
promise callback*Retryer2/run2/< retryer.js:145
promise callback*run2 retryer.js:116
Retryer2 retryer.js:156
fetch query.js:332
executeFetch queryObserver.js:199
onSubscribe queryObserver.js:40
subscribe subscribable.js:16
useBaseQuery useBaseQuery.js:60
React 13
workLoop scheduler.development.js:266
flushWork scheduler.development.js:239
performWorkUntilDeadline scheduler.development.js:533
js scheduler.development.js:571
js scheduler.development.js:633
__require2 chunk-GFT2G5UO.js:18
js index.js:6
__require2 chunk-GFT2G5UO.js:18
React 2
__require2 chunk-GFT2G5UO.js:18
js React
__require2 chunk-GFT2G5UO.js:18
js React
__require2 chunk-GFT2G5UO.js:18
<anonymous>
Activity
slax57 commentedon Aug 30, 2024
Thanks for this report!
Providing no
redirectTo
is currently not supported, but it would be nice if it was!I'll label this issue as enhancement (and good first issue). Thanks!
Reject promise in checkError with logoutUser: false and without redir…
rktamil commentedon Sep 1, 2024
I had fixed it in #10177. Could you please assign it to me ?
slax57 commentedon Oct 7, 2024
@rktamil No need to assign the issue. Referencing the issue number in your PR description is enough.
Thank you for contributing!
carloshv93 commentedon May 30, 2025
I have created a PR which solves this
slax57 commentedon Jun 19, 2025
Fixed by #10763
useLogoutAccessDenied
should not throw when noredirectTo
is provided #10763