react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

disableAuthentication prop on (Infinite)List is ignored when used on a Dashboard

Open milutinovici opened this issue 1 year ago • 5 comments

What you were expecting: I want to have a root page, that's a List, to not require authentication.

What happened instead: Page redirects to login.

  • React-admin version: 4.15.0
  • React version: 18.2.0

milutinovici avatar Oct 16 '23 14:10 milutinovici

Please follow the issue template (including a repro)

slax57 avatar Oct 17 '23 12:10 slax57

Here you go

https://stackblitz.com/edit/github-nmv8yb

milutinovici avatar Oct 18 '23 07:10 milutinovici

I see you have put disableAuthentication only on the mobile version of the List, but not on the desktop version. Is it intended?

slax57 avatar Oct 18 '23 11:10 slax57

Yeah sorry. Didn't see. I edited the template

milutinovici avatar Oct 18 '23 12:10 milutinovici

Thanks. You are correct, the dashboard route is protected by default, and this cannot be disabled via a prop.

However, when on the dashboard, react-admin will call checkAuth(params) with params = { route: 'dashboard' }.

So you can add the following line to your authProvider to disable the check for the dashboard route only:

    checkAuth: (params) => {
+       if (params?.route === 'dashboard') return Promise.resolve();
        return localStorage.getItem('not_authenticated')
            ? Promise.reject()
            : Promise.resolve();
    },

AFAICT this is not documented anywhere, so I'll leave this issue open as a doc issue.

Thanks for the report!

slax57 avatar Oct 20 '23 12:10 slax57