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

chore(auth): allow user refetch #324

Merged
merged 1 commit into from
Mar 6, 2023

Conversation

jiblett1000
Copy link
Contributor

@jiblett1000 jiblett1000 commented Mar 5, 2023

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

This is a small but important change. This separates the guard logic in the fetchUser method so that it maintains the current functionality while allowing the developer to refetch the user data when/if desired.

By putting if (!user) around the fetchUser call in the plugin we maintain that it will only be called once when there is no user state. Then, we we leave the if (token) within the fetchUser method to maintain security.

Use case:

While building a profile page, I needed to update the user avatar and info. The avatar in particular posed a bigger problem. I needed to refresh the user info after uploading it. However, after banging my head against the wall for a bit while trying to use the fetchUser method, I realized the !user.value guard in the method meant that it would never refetch the user data when a user was logged in. I moved that logic to the plugin and bingo, the avatar refreshed as intended.

That's about it. Thanks for reading!

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes (if not applicable, please state why)

@jiblett1000 jiblett1000 changed the title feat: Allow user refetch feat: allow user refetch Mar 5, 2023
@benjamincanac
Copy link
Member

@jiblett1000 Thanks for the PR, indeed it makes sense!

@benjamincanac benjamincanac changed the title feat: allow user refetch chore(auth): allow user refetch Mar 6, 2023
@benjamincanac benjamincanac merged commit 825c7d8 into nuxt-modules:dev Mar 6, 2023
jiblett1000 added a commit to jiblett1000/strapi-module that referenced this pull request Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants