Files
ims/app/report/page.tsx
T
adminandClaude Sonnet 4.6 d18d29168a 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>
2026-07-23 16:20:04 +08:00

68 lines
2.2 KiB
TypeScript

export const dynamic = 'force-dynamic'
import { redirect } from 'next/navigation'
import { createClient } from '@/lib/supabase/server'
import { getSession } from '@/lib/auth/get-session'
import { ReportForm } from '@/components/incidents/report-form'
import { LanguageSwitcher } from '@/components/language-switcher'
import { OfflineSync } from '@/components/incidents/offline-sync'
interface Props {
searchParams: Promise<{ zone?: string; truck_id?: string }>
}
export default async function ReportPage({ searchParams }: Props) {
const { zone, truck_id } = await searchParams
const session = await getSession()
if (!session) redirect(`/login?redirect=/report${zone ? `?zone=${zone}` : ''}`)
const supabase = await createClient()
let zoneName: string | null = null
let siteName: string | null = null
if (zone) {
const { data: zd } = await supabase
.from('zones')
.select('id, name, site_id, sites (name)')
.eq('qr_code_token', zone)
.single()
if (zd) {
zoneName = (zd as { name: string }).name ?? null
siteName = (zd.sites as unknown as { name: string } | null)?.name ?? null
}
}
const { data: trucks } = await supabase
.from('trucks')
.select('id, truck_no, carrier')
.eq('active', true)
.order('truck_no')
return (
<main className="min-h-screen bg-gray-50 py-6 px-4 max-w-lg mx-auto">
<div className="mb-6">
<div className="flex items-center justify-between">
<h1 className="text-2xl font-bold text-gray-900">{/* will be translated via ReportForm */}Report an Incident</h1>
<LanguageSwitcher />
</div>
{zoneName ? (
<p className="text-sm text-gray-600 mt-1">
{siteName ?? 'Unknown Site'} {zoneName}
</p>
) : (
<p className="text-sm text-amber-600 mt-1">No zone detected zone will not be recorded</p>
)}
</div>
<ReportForm
zoneToken={zone ?? null}
zoneName={zoneName}
siteName={siteName}
trucks={(trucks ?? []) as Array<{ id: string; truck_no: string; carrier: string | null }>}
initialTruckId={truck_id ?? null}
/>
<OfflineSync />
</main>
)
}