mirror of
https://github.com/multipleof4/KalBot.git
synced 2026-03-16 21:41:02 +00:00
Feat: Implement signed HttpOnly session cookie
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
|
import { signSession } from '../../../lib/auth';
|
||||||
|
|
||||||
export async function POST(req) {
|
export async function POST(req) {
|
||||||
try {
|
try {
|
||||||
@@ -15,8 +16,21 @@ 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) {
|
||||||
// Real implementation would set a JWT or session cookie here
|
// Generate our secure edge-compatible token
|
||||||
return NextResponse.json({ success: true, message: 'Welcome back, Master!' });
|
const token = await signSession();
|
||||||
|
|
||||||
|
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, {
|
||||||
|
httpOnly: true,
|
||||||
|
secure: process.env.NODE_ENV === 'production',
|
||||||
|
sameSite: 'strict',
|
||||||
|
path: '/',
|
||||||
|
maxAge: 60 * 60 * 24 // 1 day in seconds
|
||||||
|
});
|
||||||
|
|
||||||
|
return response;
|
||||||
} else {
|
} else {
|
||||||
// Trigger NTFY alert for failed login
|
// Trigger NTFY alert for failed login
|
||||||
if (process.env.NTFY_URL) {
|
if (process.env.NTFY_URL) {
|
||||||
|
|||||||
Reference in New Issue
Block a user