Skip to content

Commit

Permalink
fix:lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Chulinuwu committed Dec 19, 2024
1 parent efae2c3 commit 4ae69c1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
36 changes: 18 additions & 18 deletions src/lib/api/login.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const API_URL = '/api/login';
export async function login(studentId: string, password: string) {
try {
const response = await fetch(API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ studentId, password })
});
try {
const response = await fetch(API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ studentId, password })
});

if (!response.ok) {
throw new Error('Login failed');
}
if (!response.ok) {
throw new Error('Login failed');
}

const data = await response.json();
return data;
} catch (error) {
console.error(error);
throw error;
}
}
const data = await response.json();
return data;
} catch (error) {
console.error(error);
throw error;
}
}
40 changes: 20 additions & 20 deletions src/routes/api/login/+server.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import type { RequestHandler } from '@sveltejs/kit';

export const POST: RequestHandler = async ({ request }) => {
const { studentId, password } = await request.json();
const { studentId, password } = await request.json();

const response = await fetch(`${import.meta.env.VITE_SERVER_URL}/api/v1/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ student_id: studentId, password })
});
const response = await fetch(`${import.meta.env.VITE_SERVER_URL}/api/v1/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ student_id: studentId, password })
});

if (!response.ok) {
return new Response(JSON.stringify({ error: 'Login failed' }), {
status: response.status,
headers: { 'Content-Type': 'application/json' }
});
}
if (!response.ok) {
return new Response(JSON.stringify({ error: 'Login failed' }), {
status: response.status,
headers: { 'Content-Type': 'application/json' }
});
}

const data = await response.json();
return new Response(JSON.stringify(data), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
};
const data = await response.json();
return new Response(JSON.stringify(data), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
};

0 comments on commit 4ae69c1

Please sign in to comment.