From d1233207978bd8bba2b5eaa55b4b31240fb3ea9c Mon Sep 17 00:00:00 2001 From: qowevisa Date: Wed, 20 Nov 2024 18:22:03 +0200 Subject: [PATCH] Add api/auth/register proxy request --- src/routes/api/auth/register/+server.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/routes/api/auth/register/+server.ts 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 }); + } +} +