Skip to content

Conversation

@Lansa-18
Copy link

closes #410

Description

Implemented a global authentication state management solution using Zustand with localStorage persistence and secure cookie synchronization for seamless SSR/CSR authentication in ManageHub.

Acceptance Criteria Met

State Management

  • accessToken - JWT access token
  • refreshToken - Token for refresh flow
  • user - Complete user profile object
  • isAuthenticated - Boolean authentication status
  • tokenExpiresAt - Token expiration timestamp

Core Actions

  • setAuth() - Sets authentication state with auto-calculated expiry
  • updateUser() - Merges partial user updates
  • clearAuth() - Clears state and removes all cookies/storage

Persistence & Synchronization

  • localStorage persistence with key "auth-storage"
  • Cookie sync for accessToken
  • 7-day cookie expiry
  • Secure cookies with SameSite=Strict and Secure=true
  • Automatic cleanup on logout

Developer Experience

  • Helper selectors: useIsAuthenticated(), useUser(), useToken()
  • Additional selectors: useRefreshToken(), useTokenExpiresAt(), useAuthActions()
  • Hydration guard: useHasHydrated() for SSR safety

@vercel
Copy link

vercel bot commented Jan 24, 2026

@Lansa-18 is attempting to deploy a commit to the naijabuz's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

FRONTEND: Setup Zustand Auth Store with Persistence

1 participant