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

Reject promise in checkError with logoutUser: false and without redirectTo causes an error #10172

Open
thibault-barrat opened this issue Aug 30, 2024 · 3 comments · May be fixed by #10177
Open

Comments

@thibault-barrat
Copy link
Contributor

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 :

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>
@slax57
Copy link
Contributor

slax57 commented 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!

rktamil added a commit to rktamil/react-admin that referenced this issue Sep 1, 2024
@rktamil
Copy link

rktamil commented Sep 1, 2024

I had fixed it in #10177. Could you please assign it to me ?

@slax57
Copy link
Contributor

slax57 commented Oct 7, 2024

@rktamil No need to assign the issue. Referencing the issue number in your PR description is enough.
Thank you for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants