feat(auth): harden session management and security
- Implement server-side session revocation on logout - Add IP extraction utility and admin setup error handling - Improve error codes and response consistency for auth endpoints - Refine landing page redirect logic to handle transient DB outages - Update deployment documentation and configuration defaults
This commit is contained in:
1 parent
935f12a1e9
commit
89e4d68690
81 files changed
+11530
-6916
No files matched your search
+46
-8
@@ -1,12 +1,50 @@
|
||||
'use client';
|
||||
|
||||
import { MainLayout } from '@/components/layout/MainLayout';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { VconShell } from '@/components/layout/VconShell';
|
||||
import { verifyRequestAdminSession } from '@/core/auth/adminUsers';
|
||||
import { cookies, headers } from 'next/headers';
|
||||
import { redirect } from 'next/navigation';
|
||||
import React from 'react';
|
||||
|
||||
export default function VconLayout({ children }: { children: React.ReactNode }) {
|
||||
const pathname = usePathname();
|
||||
if (pathname === '/vcon/login' || pathname === '/vcon/setup') return <>{children}</>;
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
return <MainLayout showSidebar={true}>{children}</MainLayout>;
|
||||
export default async function VconLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const headerList = await headers();
|
||||
const pathname = headerList.get('x-datastack-pathname') || '';
|
||||
|
||||
if (pathname === '/vcon/login' || pathname === '/vcon/setup') {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
const cookieStore = await cookies();
|
||||
const token = cookieStore.get('datastack_admin_session')?.value;
|
||||
const auth = await verifyRequestAdminSession(token);
|
||||
|
||||
if (!auth.valid) {
|
||||
if (auth.reason === 'UNAUTHORIZED') {
|
||||
const loginTarget = pathname
|
||||
? `/vcon/login?next=${encodeURIComponent(pathname)}`
|
||||
: '/vcon/login';
|
||||
redirect(loginTarget);
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="grid min-h-dvh place-items-center bg-[var(--bg)] p-4 text-[var(--text)]">
|
||||
<section className="w-full max-w-sm border border-[var(--border)] bg-[var(--surface)] p-5">
|
||||
<h1 className="text-[13px] font-medium text-[var(--text)]">
|
||||
Console authentication unavailable
|
||||
</h1>
|
||||
<p className="mt-2 text-[12px] text-[var(--text-muted)]">
|
||||
{auth.reason === 'UNCONFIGURED'
|
||||
? 'Admin session secret is not configured.'
|
||||
: 'Database authentication check is temporarily unavailable. Please retry shortly.'}
|
||||
</p>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
return <VconShell>{children}</VconShell>;
|
||||
}
|
||||
Reference in new issue
Block a user