Skip to content

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

@thibault-barrat

Description

@thibault-barrat
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>

Activity

slax57

slax57 commented on Aug 30, 2024

@slax57
Contributor

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

rktamil commented on Sep 1, 2024

@rktamil

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

slax57

slax57 commented on Oct 7, 2024

@slax57
Contributor

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

carloshv93

carloshv93 commented on May 30, 2025

@carloshv93
Contributor

I have created a PR which solves this

slax57

slax57 commented on Jun 19, 2025

@slax57
Contributor

Fixed by #10763

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @fzaninotto@slax57@rktamil@thibault-barrat@carloshv93

      Issue actions

        Reject promise in checkError with logoutUser: false and without redirectTo causes an error · Issue #10172 · marmelab/react-admin