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
+32
-4
@@ -1,18 +1,46 @@
|
||||
import { AdminLogin } from '@/components/sections/AdminLogin';
|
||||
import { isAdminSetupComplete } from '@/core/auth/adminUsers';
|
||||
import {
|
||||
isAdminSetupComplete,
|
||||
verifyRequestAdminSession,
|
||||
} from '@/core/auth/adminUsers';
|
||||
import { cookies } from 'next/headers';
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export default async function LoginPage() {
|
||||
const isConfigured = await isAdminSetupComplete().catch(() => false);
|
||||
if (!isConfigured) redirect('/vcon/setup');
|
||||
let databaseReady = true;
|
||||
try {
|
||||
const isConfigured = await isAdminSetupComplete();
|
||||
if (!isConfigured) redirect('/vcon/setup');
|
||||
} catch (error) {
|
||||
if (
|
||||
error &&
|
||||
typeof error === 'object' &&
|
||||
'digest' in error &&
|
||||
String((error as { digest?: unknown }).digest).startsWith('NEXT_REDIRECT')
|
||||
) {
|
||||
throw error;
|
||||
}
|
||||
databaseReady = false;
|
||||
}
|
||||
|
||||
if (databaseReady) {
|
||||
const cookieStore = await cookies();
|
||||
const token = cookieStore.get('datastack_admin_session')?.value;
|
||||
if (token) {
|
||||
const auth = await verifyRequestAdminSession(token);
|
||||
if (auth.valid) {
|
||||
redirect('/vcon/dashboard');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const showDemoHint =
|
||||
!process.env.DATABASE_URL &&
|
||||
process.env.NODE_ENV !== 'production' &&
|
||||
process.env.DATASTACK_ALLOW_DEMO_ADMIN !== 'false';
|
||||
|
||||
return <AdminLogin showDemoHint={showDemoHint} />;
|
||||
return <AdminLogin showDemoHint={showDemoHint} databaseReady={databaseReady} />;
|
||||
}
|
||||
Reference in new issue
Block a user