feat(accounts): add admin accounts and user preferences

Remove public registration, support administrator-managed accounts, and persist personal preferences.

Refs #2 #5

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 19:54:06 +01:00
parent 1b0625f91c
commit 50bde816ed
46 changed files with 1362 additions and 256 deletions

View File

@ -1,20 +1,5 @@
import { createContext, useContext, useState, type ReactNode } from 'react'
interface User {
id: string
email: string
role: 'admin' | 'user'
}
interface AuthCtx {
user: User | null
token: string | null
login: (token: string, user: User) => void
logout: () => void
isAdmin: boolean
}
const AuthContext = createContext<AuthCtx | null>(null)
import { useState, type ReactNode } from 'react'
import { AuthContext, type User } from './auth'
export function AuthProvider({ children }: { children: ReactNode }) {
const [token, setToken] = useState<string | null>(() => localStorage.getItem('token'))
@ -44,8 +29,3 @@ export function AuthProvider({ children }: { children: ReactNode }) {
)
}
export function useAuth() {
const ctx = useContext(AuthContext)
if (!ctx) throw new Error('useAuth must be used within AuthProvider')
return ctx
}

23
frontend/src/lib/auth.ts Normal file
View File

@ -0,0 +1,23 @@
import { createContext, useContext } from 'react'
export interface User {
id: string
email: string
role: 'admin' | 'user'
}
interface AuthCtx {
user: User | null
token: string | null
login: (token: string, user: User) => void
logout: () => void
isAdmin: boolean
}
export const AuthContext = createContext<AuthCtx | null>(null)
export function useAuth() {
const ctx = useContext(AuthContext)
if (!ctx) throw new Error('useAuth must be used within AuthProvider')
return ctx
}

View File

@ -12,6 +12,7 @@ import { Jobs } from '@/pages/admin/Jobs'
import { AdminUsers } from '@/pages/admin/AdminUsers'
import { AdminSettings } from '@/pages/admin/AdminSettings'
import { Schedule } from '@/pages/admin/Schedule'
import { Preferences } from '@/pages/Preferences'
import { Reports } from '@/pages/Reports'
export const router = createBrowserRouter([
@ -22,6 +23,7 @@ export const router = createBrowserRouter([
{ path: '/', element: <Dashboard /> },
{ path: '/feed', element: <Feed /> },
{ path: '/watchlist', element: <Watchlist /> },
{ path: '/preferences', element: <Preferences /> },
{ path: '/reports', element: <Reports /> },
{
path: '/admin',

View File

@ -1,13 +1,5 @@
import { createContext, useContext, useEffect, useState, type ReactNode } from 'react'
type Theme = 'light' | 'dark'
interface ThemeCtx {
theme: Theme
setTheme: (t: Theme) => void
}
const ThemeContext = createContext<ThemeCtx | null>(null)
import { useState, type ReactNode, useEffect } from 'react'
import { ThemeContext, type Theme } from './theme'
export function ThemeProvider({ children }: { children: ReactNode }) {
const [theme, setThemeState] = useState<Theme>(() => {
@ -33,8 +25,3 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
)
}
export function useTheme() {
const ctx = useContext(ThemeContext)
if (!ctx) throw new Error('useTheme must be used within ThemeProvider')
return ctx
}

16
frontend/src/lib/theme.ts Normal file
View File

@ -0,0 +1,16 @@
import { createContext, useContext } from 'react'
export type Theme = 'light' | 'dark'
interface ThemeCtx {
theme: Theme
setTheme: (t: Theme) => void
}
export const ThemeContext = createContext<ThemeCtx | null>(null)
export function useTheme() {
const ctx = useContext(ThemeContext)
if (!ctx) throw new Error('useTheme must be used within ThemeProvider')
return ctx
}