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

Fetch user before pass it to the restricted function #6293

Merged
merged 4 commits into from
Oct 3, 2024
Merged

Conversation

wesleybl
Copy link
Member

It may not be in the Redux store yet when we try to pass it in. So we dispatch if it's not in the store.

Copy link

netlify bot commented Sep 16, 2024

Deploy Preview for plone-components canceled.

Name Link
🔨 Latest commit bd5c4cc
🔍 Latest deploy log https://app.netlify.com/sites/plone-components/deploys/66f459dc81d2b60008afd328

packages/volto/src/components/theme/Login/Login.jsx Outdated Show resolved Hide resolved
packages/volto/src/hooks/user/useUser.js Outdated Show resolved Hide resolved
Copy link
Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pnicolli
Copy link
Contributor

I am not sure I understand what problem we are trying to solve here. Aren't the components getting an update (rerender triggered by useSelector) when the user is finally fetched, even if it's not there when these components are first rendered? In other words, does it break somehow, or what is the issue here?
I'm trying to understand if we are firing an extra query to the backend that is worth firing or if it can be avoided. Moreover, would it be possible, if we have a use case for fetching user data here, to just do it during SSR instead? This way we could potentially avoid any issue from the beginning.

@davisagli
Copy link
Member

@pnicolli Consider the case where the user is logged out, then they log in and edit the page. Then we have to dispatch getUser, because the user isn't in the store yet. In this scenario there is no SSR request at a point in time when the user is logged in.

@sneridagh
Copy link
Member

@pnicolli this is related to #6271, as a continuation, if the user info is not in the store, this PR makes sure it's in there, so we can use it in a restrict key in the block config.

It LGTM.

@sneridagh sneridagh merged commit 6e498de into main Oct 3, 2024
71 checks passed
@sneridagh sneridagh deleted the dispatch_user branch October 3, 2024 06:51
@pnicolli
Copy link
Contributor

pnicolli commented Oct 3, 2024

@pnicolli Consider the case where the user is logged out, then they log in and edit the page. Then we have to dispatch getUser, because the user isn't in the store yet. In this scenario there is no SSR request at a point in time when the user is logged in.

I thought the user should get into the store eventually when the user logs into the portal, but I trust you to have done more research than I did on the subject 😁 👍

@sneridagh
Copy link
Member

@pnicolli not the case, but it's a good point. @davisagli thoughts?

@pnicolli
Copy link
Contributor

pnicolli commented Oct 3, 2024

Well I was thinking... maybe we should consider for Volto 19 to move the user info to an expander we get with the content? Would it be worth it? I don't want to clutter anybody's notifications though, so maybe I could give this a little more thought and discuss it at a Volto Team meeting

@davisagli
Copy link
Member

I also had the idea of fetching the user info when the user logs in, but it doesn't avoid the need for what we have in this PR, because sometimes the user loads the page from the server while already logged in.

I don't think user info belongs in an expander because it's information that does not depend on which content item is being fetched. It would also make it hard to cache content responses in a way that is shared between multiple users with the same roles.

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

Successfully merging this pull request may close these issues.

5 participants