@@ -40,10 +30,7 @@ export default async function NewCapaPage({ params }: Props) {
{(incident as { reference_no: string | null }).reference_no ?? id}
- }
- />
+
)
}
diff --git a/app/api/auth/callback/route.ts b/app/api/auth/callback/route.ts
index c1d5816..edfe745 100644
--- a/app/api/auth/callback/route.ts
+++ b/app/api/auth/callback/route.ts
@@ -1,20 +1,24 @@
-// app/api/auth/callback/route.ts
import { createClient } from '@/lib/supabase/server'
import { NextResponse } from 'next/server'
+import type { EmailOtpType } from '@supabase/supabase-js'
export async function GET(request: Request) {
const { searchParams } = new URL(request.url)
const code = searchParams.get('code')
+ const token_hash = searchParams.get('token_hash')
+ const type = searchParams.get('type') as EmailOtpType | null
const nextRaw = searchParams.get('next') ?? '/'
const next = nextRaw.startsWith('/') && !nextRaw.startsWith('//') ? nextRaw : '/'
const appUrl = (process.env.NEXT_PUBLIC_APP_URL ?? '').replace(/\/$/, '')
+ const supabase = await createClient()
+
if (code) {
- const supabase = await createClient()
const { error } = await supabase.auth.exchangeCodeForSession(code)
- if (!error) {
- return NextResponse.redirect(`${appUrl}${next}`)
- }
+ if (!error) return NextResponse.redirect(`${appUrl}${next}`)
+ } else if (token_hash && type) {
+ const { error } = await supabase.auth.verifyOtp({ token_hash, type })
+ if (!error) return NextResponse.redirect(`${appUrl}${next}`)
}
return NextResponse.redirect(`${appUrl}/login?error=auth_callback_failed`)
diff --git a/app/api/capa/[id]/route.ts b/app/api/capa/[id]/route.ts
index e44b053..21e6029 100644
--- a/app/api/capa/[id]/route.ts
+++ b/app/api/capa/[id]/route.ts
@@ -2,6 +2,7 @@ export const dynamic = 'force-dynamic'
import { NextRequest, NextResponse } from 'next/server'
import { createClient } from '@/lib/supabase/server'
+import { createAdminClient } from '@/lib/supabase/admin'
export async function GET(
_: NextRequest,
@@ -74,7 +75,8 @@ export async function PATCH(
update.completed_at = new Date().toISOString()
}
- const { error } = await supabase
+ const admin = createAdminClient()
+ const { error } = await admin
.from('capa_actions')
.update(update)
.eq('id', id)
diff --git a/app/api/capa/route.ts b/app/api/capa/route.ts
index ef7d2a5..b6f98ba 100644
--- a/app/api/capa/route.ts
+++ b/app/api/capa/route.ts
@@ -45,7 +45,7 @@ export async function POST(request: NextRequest) {
const body = await request.json()
const { incident_id, description, owner_user_id, department, due_date, priority, root_cause_ref } = body
- if (!incident_id || !description || !owner_user_id || !department || !due_date)
+ if (!incident_id || !description || !owner_user_id || !due_date)
return NextResponse.json({ error: 'Missing required fields' }, { status: 422 })
const { data: capa, error } = await supabase
@@ -54,7 +54,7 @@ export async function POST(request: NextRequest) {
incident_id,
description,
owner_user_id,
- department,
+ department: department || '',
due_date,
priority: priority ?? 'med',
root_cause_ref: root_cause_ref ?? null,
diff --git a/components/capa/capa-form.tsx b/components/capa/capa-form.tsx
index 1fc8ec5..c1426bc 100644
--- a/components/capa/capa-form.tsx
+++ b/components/capa/capa-form.tsx
@@ -1,6 +1,6 @@
'use client'
-import { useState } from 'react'
+import { useState, useEffect } from 'react'
import { useRouter } from 'next/navigation'
interface User {
@@ -11,11 +11,11 @@ interface User {
interface Props {
incidentId: string
- users: User[]
}
-export function CapaForm({ incidentId, users }: Props) {
+export function CapaForm({ incidentId }: Props) {
const router = useRouter()
+ const [users, setUsers] = useState