feat(auth): phase 3 — replace Supabase GoTrue with bcryptjs+jose
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>
This commit is contained in:
@@ -1,18 +1,12 @@
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import type { SupabaseClient } from '@supabase/supabase-js'
|
||||
import type { User } from '@supabase/supabase-js'
|
||||
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 user: null when the caller must respond 403.
|
||||
// the admin role. Returns session: null when the caller must respond 403.
|
||||
export async function requireAdmin(): Promise<{
|
||||
supabase: SupabaseClient
|
||||
user: User | null
|
||||
session: SessionPayload | null
|
||||
}> {
|
||||
const supabase = await createClient()
|
||||
const { data: { user }, error } = await supabase.auth.getUser()
|
||||
if (error || !user) return { supabase, user: null }
|
||||
const { data: profile } = await supabase
|
||||
.from('users').select('role').eq('id', user.id).single()
|
||||
if (!profile || profile.role !== 'admin') return { supabase, user: null }
|
||||
return { supabase, user }
|
||||
const session = await getSession()
|
||||
if (!session || session.role !== 'admin') return { session: null }
|
||||
return { session }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user