- Implement complete authentication system with JWT token validation - Add auth provider with persistent login state across page refreshes - Create multilingual login/register forms with Material-UI components - Fix token validation using raw SQL queries to bypass Prisma sync issues - Add comprehensive error handling for expired/invalid tokens - Create profile and settings pages with full i18n support - Add proper user role management (admin/user) with database sync - Implement secure middleware with CSRF protection and auth checks - Add debug endpoints for troubleshooting authentication issues - Fix Zustand store persistence for authentication state 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { create } from 'zustand'
|
|
import { persist } from 'zustand/middleware'
|
|
import { User, Bookmark } from '@/types'
|
|
|
|
interface AppState {
|
|
user: User | null
|
|
theme: 'light' | 'dark'
|
|
fontSize: 'small' | 'medium' | 'large'
|
|
currentBook: number
|
|
currentChapter: number
|
|
bookmarks: Bookmark[]
|
|
setUser: (user: User | null) => void
|
|
setTheme: (theme: 'light' | 'dark') => void
|
|
setFontSize: (size: 'small' | 'medium' | 'large') => void
|
|
setCurrentBook: (book: number) => void
|
|
setCurrentChapter: (chapter: number) => void
|
|
addBookmark: (bookmark: Bookmark) => void
|
|
removeBookmark: (bookmarkId: string) => void
|
|
}
|
|
|
|
export const useStore = create<AppState>()(
|
|
persist(
|
|
(set) => ({
|
|
user: null,
|
|
theme: 'light',
|
|
fontSize: 'medium',
|
|
currentBook: 1,
|
|
currentChapter: 1,
|
|
bookmarks: [],
|
|
setUser: (user) => set({ user }),
|
|
setTheme: (theme) => set({ theme }),
|
|
setFontSize: (fontSize) => set({ fontSize }),
|
|
setCurrentBook: (currentBook) => set({ currentBook }),
|
|
setCurrentChapter: (currentChapter) => set({ currentChapter }),
|
|
addBookmark: (bookmark) => set((state) => ({
|
|
bookmarks: [...state.bookmarks, bookmark]
|
|
})),
|
|
removeBookmark: (bookmarkId) => set((state) => ({
|
|
bookmarks: state.bookmarks.filter(b => b.id !== bookmarkId)
|
|
})),
|
|
}),
|
|
{
|
|
name: 'bible-chat-storage',
|
|
partialize: (state) => ({
|
|
user: state.user,
|
|
theme: state.theme,
|
|
fontSize: state.fontSize,
|
|
currentBook: state.currentBook,
|
|
currentChapter: state.currentChapter,
|
|
bookmarks: state.bookmarks,
|
|
}),
|
|
}
|
|
)
|
|
) |