Review
Keep day-player sessions warm across call-sheet reloads
FilmLedger day-players open paystubs on shared craft-services iPads between takes and lose session on every full reload. Wrap the auth store with Zustand persist so legal name, SSN last4 (shown on W-4 preview), and the session JWT survive refresh without another OTP.
ZustandTier 2securityzustandlocalStoragepii
Click a line to flag it, pick one or more labels, then submit. If the change looks correct, approve it.
src/stores/authStore.ts+12-6
| 1 | 1 | import { create } from "zustand"; | |
| 2 | + | import { persist } from "zustand/middleware"; | |
| 2 | 3 | ||
| 3 | 4 | export type CrewUser = { | |
| 4 | 5 | id: string; | |
| 5 | 6 | legalName: string; | |
| 6 | 7 | ssnLast4: string; | |
| 7 | 8 | unionLocal: string; | |
| 8 | 9 | }; | |
| 9 | 10 | ||
| 10 | 11 | type AuthState = { | |
| 11 | 12 | user: CrewUser | null; | |
| 12 | 13 | accessToken: string | null; | |
| 13 | 14 | setSession: (user: CrewUser, token: string) => void; | |
| 14 | 15 | clearSession: () => void; | |
| 15 | 16 | }; | |
| 16 | 17 | ||
| 17 | - | export const useAuthStore = create<AuthState>((set) => ({ | |
| 18 | - | user: null, | |
| 19 | - | accessToken: null, | |
| 20 | - | setSession: (user, accessToken) => set({ user, accessToken }), | |
| 21 | - | clearSession: () => set({ user: null, accessToken: null }), | |
| 22 | - | })); | |
| 18 | + | export const useAuthStore = create<AuthState>()( | |
| 19 | + | persist( | |
| 20 | + | (set) => ({ | |
| 21 | + | user: null, | |
| 22 | + | accessToken: null, | |
| 23 | + | setSession: (user, accessToken) => set({ user, accessToken }), | |
| 24 | + | clearSession: () => set({ user: null, accessToken: null }), | |
| 25 | + | }), | |
| 26 | + | { name: "filmledger-auth" }, | |
| 27 | + | ), | |
| 28 | + | ); |