Converts all 18 server component page files from Supabase client queries to Drizzle ORM using asAdmin. Adds getSession() + redirect to the three pages (hse/incidents, hse/incidents/[id], hse/dashboard) that lacked it. Maps snake_case component prop shapes explicitly where required. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
export const dynamic = 'force-dynamic'
|
|
|
|
import { redirect } from 'next/navigation'
|
|
import { asAdmin } from '@/lib/db/with-user'
|
|
import { getSession } from '@/lib/auth/get-session'
|
|
import { appSettings } from '@/lib/db/schema'
|
|
import { ApiKeyForm } from '@/components/settings/api-key-form'
|
|
|
|
export default async function SettingsPage() {
|
|
const session = await getSession()
|
|
if (!session) redirect('/login')
|
|
if (session.role !== 'admin') redirect('/hse/dashboard')
|
|
|
|
const settingRows = await asAdmin(db =>
|
|
db.select({
|
|
key: appSettings.key,
|
|
value: appSettings.value,
|
|
updatedAt: appSettings.updatedAt,
|
|
}).from(appSettings)
|
|
)
|
|
|
|
const settingsMap = Object.fromEntries(
|
|
settingRows.map(s => [s.key, { set: Boolean(s.value), updated_at: s.updatedAt?.toISOString() ?? null }])
|
|
)
|
|
|
|
return (
|
|
<main className="max-w-2xl mx-auto px-4 py-6">
|
|
<h1 className="text-2xl font-bold text-gray-900 mb-2">Settings</h1>
|
|
<p className="text-sm text-gray-700 mb-6">
|
|
API keys are stored securely in the database. Leave blank to use environment variables.
|
|
</p>
|
|
<ApiKeyForm settings={settingsMap} />
|
|
</main>
|
|
)
|
|
}
|