Remove console.log and change type of function to RequestHandler for api/auth/login proxy request
This commit is contained in:
parent
0b11141811
commit
4ac66b2b55
|
@ -1,26 +1,16 @@
|
||||||
// src/routes/api/auth/login/+server.ts
|
// src/routes/api/auth/login/+server.ts
|
||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
import { login } from '$lib/api';
|
import { login } from '$lib/api';
|
||||||
import type { PageServerLoad } from '../../../test2/$types';
|
import type { RequestHandler } from './$types';
|
||||||
|
|
||||||
export const POST: PageServerLoad = async ({ request, cookies }) => {
|
export const POST: RequestHandler = async ({ request, cookies }) => {
|
||||||
console.log("in POST1")
|
|
||||||
const authToken = request.headers.get('App-Token');
|
const authToken = request.headers.get('App-Token');
|
||||||
console.log("authToken = ", authToken)
|
|
||||||
console.log("it should be = ", import.meta.env.VITE_AUTH_APP_TOKEN)
|
|
||||||
if (authToken !== import.meta.env.VITE_AUTH_APP_TOKEN) {
|
if (authToken !== import.meta.env.VITE_AUTH_APP_TOKEN) {
|
||||||
return json({ error: 'Forbidden' }, { status: 403 });
|
return json({ error: 'Forbidden' }, { status: 403 });
|
||||||
}
|
}
|
||||||
console.log("in POST2")
|
|
||||||
const { username, password } = await request.json();
|
const { username, password } = await request.json();
|
||||||
|
|
||||||
console.log("in POST3")
|
|
||||||
try {
|
try {
|
||||||
console.log("in POST4")
|
|
||||||
const loginResponse = await login(username, password, cookies);
|
const loginResponse = await login(username, password, cookies);
|
||||||
console.log("loginResponse = ", loginResponse)
|
|
||||||
|
|
||||||
console.log("in POST5")
|
|
||||||
return json({ id: loginResponse.id, name: loginResponse.name });
|
return json({ id: loginResponse.id, name: loginResponse.name });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return json({ error: error }, { status: 401 });
|
return json({ error: error }, { status: 401 });
|
||||||
|
|
Loading…
Reference in New Issue
Block a user