api-platform / admin

A beautiful and fully-featured administration interface builder for hypermedia APIs
https://api-platform.com/docs/admin/
MIT License
483 stars 131 forks source link

Do not display user menu if there is no auth provider #357

Closed jfthuillier closed 3 years ago

jfthuillier commented 3 years ago
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tickets https://github.com/api-platform/admin/issues/314
License MIT
Doc PR

Even when no authProvider is configured, the user menu was displayed.

alanpoulain commented 3 years ago

So we need to explicitly set it if we use authentication?

jfthuillier commented 3 years ago

I guess so, not sure why it is not initialized here : https://github.com/marmelab/react-admin/blob/master/packages/ra-core/src/core/CoreAdminUI.tsx#L59

alanpoulain commented 3 years ago

It is in the AdminUI: https://github.com/marmelab/react-admin/blob/b1a66701d79ba739bddf42b7722fac0873f53464/packages/react-admin/src/AdminUI.tsx#L17

I don't think we should disable it by default. I think React Admin has made the choice to have it by default because an admin is very often used with authentication. And we should probably do the same.

However maybe we could disable the user menu (not just the logout button) if there is no auth provider? I think it should be doable with the useAuthProvider hook (I think it can be used inside the AdminResourcesGuesser since the admin context is a parent).

jfthuillier commented 3 years ago

I did not manage to use the hook inside the AdminResourcesGuesser but i have used it in the AppBar to set the userMenu value. WDYT ?

alanpoulain commented 3 years ago

Yes why not :slightly_smiling_face: It just means that whenever the user changes the default AppBar, it will have a user menu.

alanpoulain commented 3 years ago

Out of curiosity, why it was not working in the AdminResourcesGuesser?

jfthuillier commented 3 years ago

I did not find a property i could use at this level, that's why i had to change the behavior directly in the AppBar

alanpoulain commented 3 years ago

Thank you again @jfthuillier.