-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } | ||
}); | ||
}; |