refactor: standardize session cookie configuration
Centralize cookie security options to dynamically detect HTTPS, ensure secure transport, and update client-side auth handlers to use explicit credential inclusion for cookie-based sessions.
This commit is contained in:
1 parent
fde2c86b1e
commit
b42029f67d
8 files changed
+80
-53
No files matched your search
@@ -5,7 +5,6 @@ import { FormSwitch } from '@/components/ui/Form';
|
||||
import { Input } from '@/components/ui/Input';
|
||||
import { ArrowRight } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
function safeNextPath() {
|
||||
@@ -16,7 +15,6 @@ function safeNextPath() {
|
||||
}
|
||||
|
||||
export function AdminLogin() {
|
||||
const router = useRouter();
|
||||
const [email, setEmail] = useState('admin@datastack.dev');
|
||||
const [password, setPassword] = useState('admin12345678');
|
||||
const [remember, setRemember] = useState(true);
|
||||
@@ -50,12 +48,16 @@ export function AdminLogin() {
|
||||
const response = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({ email, password, remember }),
|
||||
});
|
||||
const body = await response.json();
|
||||
if (!response.ok) throw new Error(body.error || 'Sign in failed.');
|
||||
router.replace(safeNextPath());
|
||||
router.refresh();
|
||||
const targetPath = safeNextPath();
|
||||
window.location.assign(targetPath);
|
||||
window.setTimeout(() => {
|
||||
setIsSubmitting(false);
|
||||
}, 2500);
|
||||
} catch (submitError) {
|
||||
setErrorMessage(submitError instanceof Error ? submitError.message : 'Unable to sign in.');
|
||||
setIsSubmitting(false);
|
||||
|
||||
@@ -4,7 +4,6 @@ import { Button } from '@/components/ui/Button';
|
||||
import { Input } from '@/components/ui/Input';
|
||||
import { ArrowRight } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
|
||||
export function AdminSetup({
|
||||
@@ -14,7 +13,6 @@ export function AdminSetup({
|
||||
databaseReady?: boolean;
|
||||
initialEmail?: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [email, setEmail] = useState(initialEmail || 'admin@datastack.dev');
|
||||
const [password, setPassword] = useState('');
|
||||
const [confirmPassword, setConfirmPassword] = useState('');
|
||||
@@ -42,12 +40,15 @@ export function AdminSetup({
|
||||
const response = await fetch('/api/auth/setup', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({ email, password, setupKey }),
|
||||
});
|
||||
const body = await response.json();
|
||||
if (!response.ok) throw new Error(body.error || 'Admin setup failed.');
|
||||
router.replace('/vcon/dashboard');
|
||||
router.refresh();
|
||||
window.location.assign('/vcon/dashboard');
|
||||
window.setTimeout(() => {
|
||||
setIsSubmitting(false);
|
||||
}, 2500);
|
||||
} catch (submitError) {
|
||||
setErrorMessage(
|
||||
submitError instanceof Error ? submitError.message : 'Admin setup failed.',
|
||||
|
||||
Reference in new issue
Block a user