Add local authentication option (#37)
All checks were successful
Build and Push Image / docker-build-and-push (push) Successful in 2m20s
All checks were successful
Build and Push Image / docker-build-and-push (push) Successful in 2m20s
Co-authored-by: Shaun Campbell <shaun@campbellwireless.net> Reviewed-on: #37 Co-authored-by: AI Agent <ai-agent@campbellwireless.net> Co-committed-by: AI Agent <ai-agent@campbellwireless.net>
This commit was merged in pull request #37.
This commit is contained in:
@@ -4,13 +4,13 @@ import { requireAdmin } from '$lib/server/admin/auth.js';
|
||||
import * as data from '$lib/server/admin/data.js';
|
||||
|
||||
export const GET: RequestHandler = async (event) => {
|
||||
requireAdmin((await event.locals.auth())?.user?.id);
|
||||
requireAdmin((await event.locals.auth())?.user);
|
||||
const q = event.url.searchParams.get('q') ?? undefined;
|
||||
return json(data.listCountries(q));
|
||||
};
|
||||
|
||||
export const POST: RequestHandler = async (event) => {
|
||||
requireAdmin((await event.locals.auth())?.user?.id);
|
||||
requireAdmin((await event.locals.auth())?.user);
|
||||
const body = await event.request.json();
|
||||
const { name, country_code } = body as { name?: string; country_code?: string };
|
||||
if (!name?.trim() || !country_code?.trim()) {
|
||||
@@ -20,7 +20,7 @@ export const POST: RequestHandler = async (event) => {
|
||||
};
|
||||
|
||||
export const PATCH: RequestHandler = async (event) => {
|
||||
requireAdmin((await event.locals.auth())?.user?.id);
|
||||
requireAdmin((await event.locals.auth())?.user);
|
||||
const body = await event.request.json();
|
||||
const { id, name, country_code } = body as { id?: number; name?: string; country_code?: string };
|
||||
if (id == null || !name?.trim() || !country_code?.trim()) {
|
||||
@@ -31,7 +31,7 @@ export const PATCH: RequestHandler = async (event) => {
|
||||
};
|
||||
|
||||
export const DELETE: RequestHandler = async (event) => {
|
||||
requireAdmin((await event.locals.auth())?.user?.id);
|
||||
requireAdmin((await event.locals.auth())?.user);
|
||||
const id = parseInt(event.url.searchParams.get('id') ?? '');
|
||||
if (isNaN(id)) return json({ error: 'id required' }, { status: 400 });
|
||||
data.deleteCountry(id);
|
||||
|
||||
Reference in New Issue
Block a user