mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-04 04:35:19 +02:00
feat: Add session cookie to API requests in profile page server load
This commit is contained in:
parent
00f0fc9acf
commit
af33acec66
1 changed files with 12 additions and 2 deletions
|
@ -16,14 +16,24 @@ export const load: PageServerLoad = async (event: RequestEvent) => {
|
||||||
// let sessionId = event.cookies.get('sessionid');
|
// let sessionId = event.cookies.get('sessionid');
|
||||||
let stats = null;
|
let stats = null;
|
||||||
|
|
||||||
let res = await event.fetch(`${endpoint}/api/stats/counts/${username}`, {});
|
let res = await event.fetch(`${endpoint}/api/stats/counts/${username}`, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Cookie: `sessionid=${event.cookies.get('sessionid')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
console.error('Failed to fetch user stats');
|
console.error('Failed to fetch user stats');
|
||||||
} else {
|
} else {
|
||||||
stats = await res.json();
|
stats = await res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
let userData = await event.fetch(`${endpoint}/auth/user/${username}/`);
|
let userData = await event.fetch(`${endpoint}/auth/user/${username}/`, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Cookie: `sessionid=${event.cookies.get('sessionid')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
if (!userData.ok) {
|
if (!userData.ok) {
|
||||||
return error(404, 'Not found');
|
return error(404, 'Not found');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue