Custom auth stack: bcryptjs password hashing (cost 10, GoTrue-compatible), jose JWT session cookies (edge-safe, 8hr TTL), new API routes for login/logout/reset/change-password, middleware rewritten to JWT-only verification with no DB access. All 38 protected pages and API routes migrated from supabase.auth.getUser() to getSession(). Supabase .from() queries retained for Phase 4. lib/db/index.ts refactored to lazy Proxy singleton to avoid module-level throw during Next.js build. tsc: clean, build: clean, tests: 4/4 passed Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
13 lines
475 B
TypeScript
13 lines
475 B
TypeScript
import { getSession } from '@/lib/auth/get-session'
|
|
import type { SessionPayload } from '@/lib/auth/session'
|
|
|
|
// Shared guard for /api/admin/* routes: resolves the session and requires
|
|
// the admin role. Returns session: null when the caller must respond 403.
|
|
export async function requireAdmin(): Promise<{
|
|
session: SessionPayload | null
|
|
}> {
|
|
const session = await getSession()
|
|
if (!session || session.role !== 'admin') return { session: null }
|
|
return { session }
|
|
}
|