From e682162bbc04f5b5295fa22470ab0f48a5c7a377 Mon Sep 17 00:00:00 2001 From: weeihan Date: Thu, 16 Jul 2026 21:44:12 +0800 Subject: [PATCH] fix(auth): redirect to appUrl after invite callback origin lacks /ims basePath; use NEXT_PUBLIC_APP_URL instead. Co-Authored-By: Claude Sonnet 4.6 Claude-Session: https://claude.ai/code/session_01BzvzV91UqHZKM9P58qtvrA --- .../hse/incidents/[id]/capa/new/page.tsx | 4 +++- app/api/auth/callback/route.ts | 7 ++++--- deploy.sh | 21 +++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100755 deploy.sh diff --git a/app/(protected)/hse/incidents/[id]/capa/new/page.tsx b/app/(protected)/hse/incidents/[id]/capa/new/page.tsx index 0df9811..2a776af 100644 --- a/app/(protected)/hse/incidents/[id]/capa/new/page.tsx +++ b/app/(protected)/hse/incidents/[id]/capa/new/page.tsx @@ -3,6 +3,7 @@ export const dynamic = 'force-dynamic' import { notFound, redirect } from 'next/navigation' import Link from 'next/link' import { createClient } from '@/lib/supabase/server' +import { createAdminClient } from '@/lib/supabase/admin' import { CapaForm } from '@/components/capa/capa-form' interface Props { @@ -23,7 +24,8 @@ export default async function NewCapaPage({ params }: Props) { .from('incidents').select('id, reference_no, status').eq('id', id).single() if (!incident) notFound() - const { data: users } = await supabase + const admin = createAdminClient() + const { data: users } = await admin .from('users') .select('id, name, department') .eq('role', 'capa_owner') diff --git a/app/api/auth/callback/route.ts b/app/api/auth/callback/route.ts index e1b30e3..c1d5816 100644 --- a/app/api/auth/callback/route.ts +++ b/app/api/auth/callback/route.ts @@ -3,18 +3,19 @@ import { createClient } from '@/lib/supabase/server' import { NextResponse } from 'next/server' export async function GET(request: Request) { - const { searchParams, origin } = new URL(request.url) + const { searchParams } = new URL(request.url) const code = searchParams.get('code') const nextRaw = searchParams.get('next') ?? '/' const next = nextRaw.startsWith('/') && !nextRaw.startsWith('//') ? nextRaw : '/' + const appUrl = (process.env.NEXT_PUBLIC_APP_URL ?? '').replace(/\/$/, '') if (code) { const supabase = await createClient() const { error } = await supabase.auth.exchangeCodeForSession(code) if (!error) { - return NextResponse.redirect(`${origin}${next}`) + return NextResponse.redirect(`${appUrl}${next}`) } } - return NextResponse.redirect(`${origin}/login?error=auth_callback_failed`) + return NextResponse.redirect(`${appUrl}/login?error=auth_callback_failed`) } diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..a0bfa04 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -e + +VPS="root@64.176.82.100" +REMOTE_DIR="/var/www/ims" +PORT=3003 + +echo "==> Building..." +npm run build + +echo "==> Copying static assets into standalone..." +cp -r .next/static .next/standalone/.next/static +cp -r public .next/standalone/public + +echo "==> Syncing to VPS..." +rsync -az --delete --exclude='.env' .next/standalone/ "$VPS:$REMOTE_DIR/" + +echo "==> Restarting service on VPS..." +ssh "$VPS" "systemctl restart ims" + +echo "==> Done. http://64.176.82.100/ims/"