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

feat: adjust auth store to standard #36

Closed
wants to merge 4 commits into from

Conversation

walt-it
Copy link
Contributor

@walt-it walt-it commented Oct 3, 2024

⚡ {0} - {1}

💻 What type of change is this?

  • [{3}] 💎 Feature
  • [{4}] 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Styling
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build / CI

⭐ Description

  • Makes all our stores comply with our standard, persisted stores shouldn't be written different as they should behave the same.
  • Wasn't able to test it since we don't have a login implemented. But chat GPT says this:
Yes, the token will still be persisted to localStorage even though setToken is defined outside the store definition. Here’s why:

Zustand’s setState function: The setToken function simply calls useAuthStore.setState, which is a built-in function provided by Zustand to update the store's state. This method directly interacts with the store.

Persist Middleware: When you use the persist middleware, Zustand wraps the store with additional logic to automatically synchronize any changes made to the store state with localStorage. In this case, since persist is configured to store the state under the key "authStore", any changes to the token (whether done via setToken or any other update function) will be saved to localStorage.

So, even though setToken is defined outside the store, as long as it calls useAuthStore.setState, it updates the state in a way that triggers the persist logic to store the updated token in localStorage.

📷 Screenshots

n/a

💬 Comments

n/a

✅ Checklist

Requirements

  • This change includes database migrations
  • This PR requires changes in the .env file
  • This PR requires to rebuild a table or run a cron manually
  • This PR can be merged (it is not a draft, work in progress, or blocked on another PR)

To review

  • I have tested this change locally in multiple screen sizes
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • If my task include an endpoint, I add the endpoint to Hopscotch/Postman Project
  • Any dependent changes have been merged and published in downstream modules

@github-actions github-actions bot added the WIP Work in progress or draft label Oct 3, 2024
@walt-it walt-it requested a review from ThunderNaka October 3, 2024 12:36
@github-actions github-actions bot added To Review and removed WIP Work in progress or draft labels Oct 3, 2024
Copy link
Collaborator

@ThunderNaka ThunderNaka left a comment

Choose a reason for hiding this comment

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

Seems fine!

@walt-it
Copy link
Contributor Author

walt-it commented Oct 17, 2024

Gonna close and re open with signed commits so I can merge.

@walt-it walt-it closed this Oct 17, 2024
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.

2 participants