Feat: Redirect to /dash after login

This commit is contained in:
2026-03-16 11:31:02 -07:00
parent 7115c0ae08
commit 3da40a1bf9

View File

@@ -16,32 +16,24 @@ export async function POST(req) {
} }
if (email === process.env.ADMIN_EMAIL && password === process.env.ADMIN_PASS) { if (email === process.env.ADMIN_EMAIL && password === process.env.ADMIN_PASS) {
// Generate our secure edge-compatible token
const token = await signSession(); const token = await signSession();
const response = NextResponse.json({ success: true, message: 'Welcome back, Master!', redirect: '/dash' });
const response = NextResponse.json({ success: true, message: 'Welcome back, Master!' });
// Set it as an HttpOnly cookie so JavaScript can't touch it
response.cookies.set('kalbot_session', token, { response.cookies.set('kalbot_session', token, {
httpOnly: true, httpOnly: true,
secure: process.env.NODE_ENV === 'production', secure: process.env.NODE_ENV === 'production',
sameSite: 'strict', sameSite: 'strict',
path: '/', path: '/',
maxAge: 60 * 60 * 24 // 1 day in seconds maxAge: 60 * 60 * 24
}); });
return response; return response;
} else { } else {
// Trigger NTFY alert for failed login
if (process.env.NTFY_URL) { if (process.env.NTFY_URL) {
await fetch(process.env.NTFY_URL, { await fetch(process.env.NTFY_URL, {
method: 'POST', method: 'POST',
body: `Failed login attempt for email: ${email}`, body: `Failed login attempt for email: ${email}`,
headers: { headers: { 'Title': 'Kalbot Login Alert', 'Priority': 'urgent', 'Tags': 'warning,skull' }
'Title': 'Kalbot Login Alert',
'Priority': 'urgent',
'Tags': 'warning,skull'
}
}).catch(e => console.error("Ntfy error:", e)); }).catch(e => console.error("Ntfy error:", e));
} }
return NextResponse.json({ error: 'Invalid credentials' }, { status: 401 }); return NextResponse.json({ error: 'Invalid credentials' }, { status: 401 });