mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
fix: ssr request to user; navbar positioning
This commit is contained in:
@@ -2,15 +2,33 @@ import type { PageServerLoad } from './$types';
|
||||
import { getServerToken } from '$lib/utils/auth';
|
||||
import type { User } from '$lib/types/user';
|
||||
|
||||
const apiUrl = process.env.VITE_API_URL || 'http://localhost:5050';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, fetch, cookies, url }) => {
|
||||
const { username } = params;
|
||||
const token = getServerToken(cookies);
|
||||
const res = await fetch(`/api/user/${username}`, {
|
||||
|
||||
const res = await fetch(`${apiUrl}/api/user/${username}`, {
|
||||
headers: {
|
||||
Authorization: token ? `Bearer ${token}` : ''
|
||||
}
|
||||
});
|
||||
|
||||
const user = (await res.json()) as User;
|
||||
if (res.status === 500) {
|
||||
return {
|
||||
status: 500,
|
||||
error: { message: 'Internal server error' }
|
||||
};
|
||||
}
|
||||
|
||||
const json = await res.json();
|
||||
|
||||
if (res.status !== 200) {
|
||||
return {
|
||||
status: res.status,
|
||||
error: { message: json.message || 'An error occurred' }
|
||||
};
|
||||
}
|
||||
const user = json as User;
|
||||
return { user, url: url.href };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user