diff --git a/src/routes/api/auth/register/+server.ts b/src/routes/api/auth/register/+server.ts new file mode 100644 index 0000000..7dd6c56 --- /dev/null +++ b/src/routes/api/auth/register/+server.ts @@ -0,0 +1,19 @@ +// src/routes/api/auth/login/+server.ts +import { json } from '@sveltejs/kit'; +import { register } from '$lib/api'; +import type { RequestHandler } from './$types'; + +export const POST: RequestHandler = async ({ request, cookies }) => { + const authToken = request.headers.get('App-Token'); + if (authToken !== import.meta.env.VITE_AUTH_APP_TOKEN) { + return json({ error: 'Forbidden' }, { status: 403 }); + } + const { username, password } = await request.json(); + try { + const registerResponse = await register(username, password, cookies); + return json({ id: registerResponse.id, name: registerResponse.name }); + } catch (error) { + return json({ error: error }, { status: 401 }); + } +} +