Add api/auth/register proxy request
This commit is contained in:
parent
4ac66b2b55
commit
d123320797
19
src/routes/api/auth/register/+server.ts
Normal file
19
src/routes/api/auth/register/+server.ts
Normal file
|
@ -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 });
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user