improve web ui
This commit is contained in:
@@ -1,20 +1,28 @@
|
||||
// POST /_auth/login {password} — verify the shared password (constant-time), then seal an
|
||||
// authenticated session cookie. Public (allowlisted in the gate) so an unauthenticated user
|
||||
// can actually log in.
|
||||
import { defineEventHandler, readBody, createError, useSession } from 'h3'
|
||||
import { sessionConfig, timingSafeEqual, uiPassword, type SessionData } from '../../util/auth'
|
||||
import { defineEventHandler, readBody, createError, useSession } from "h3";
|
||||
import {
|
||||
sessionConfig,
|
||||
timingSafeEqual,
|
||||
uiPassword,
|
||||
type SessionData,
|
||||
} from "../../util/auth";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const expected = uiPassword()
|
||||
if (!expected) {
|
||||
throw createError({ statusCode: 503, statusMessage: 'auth not configured' })
|
||||
}
|
||||
const body = await readBody<{ password?: string }>(event)
|
||||
const password = String(body?.password ?? '')
|
||||
if (!timingSafeEqual(password, expected)) {
|
||||
throw createError({ statusCode: 401, statusMessage: 'invalid password' })
|
||||
}
|
||||
const session = await useSession<SessionData>(event, sessionConfig())
|
||||
await session.update({ authenticated: true })
|
||||
return { ok: true }
|
||||
})
|
||||
const expected = uiPassword();
|
||||
if (!expected) {
|
||||
throw createError({
|
||||
statusCode: 503,
|
||||
statusMessage: "auth not configured",
|
||||
});
|
||||
}
|
||||
const body = await readBody<{ password?: string }>(event);
|
||||
const password = String(body?.password ?? "");
|
||||
if (!timingSafeEqual(password, expected)) {
|
||||
throw createError({ statusCode: 401, statusMessage: "invalid password" });
|
||||
}
|
||||
const session = await useSession<SessionData>(event, sessionConfig());
|
||||
await session.update({ authenticated: true });
|
||||
return { ok: true };
|
||||
});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// POST /_auth/logout — clear the session cookie.
|
||||
import { defineEventHandler, useSession } from 'h3'
|
||||
import { sessionConfig, type SessionData } from '../../util/auth'
|
||||
import { defineEventHandler, useSession } from "h3";
|
||||
import { sessionConfig, type SessionData } from "../../util/auth";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const session = await useSession<SessionData>(event, sessionConfig())
|
||||
await session.clear()
|
||||
return { ok: true }
|
||||
})
|
||||
const session = await useSession<SessionData>(event, sessionConfig());
|
||||
await session.clear();
|
||||
return { ok: true };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user