1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-05 05:05:17 +02:00

User profile viewing - need to add more to the details view

This commit is contained in:
Sean Morley 2024-09-08 00:56:52 -04:00
parent a70b1f2818
commit 7d228b302b
6 changed files with 135 additions and 2 deletions

View file

@ -0,0 +1,29 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
export const load = (async (event) => {
if (!event.cookies.get('auth')) {
return redirect(302, '/login');
}
const uuid = event.params.uuid;
if (!uuid) {
return redirect(302, '/users');
}
let res = await fetch(`${serverEndpoint}/auth/user/${uuid}/`, {
headers: {
Cookie: `${event.cookies.get('auth')}`
}
});
if (!res.ok) {
return redirect(302, '/users');
} else {
const data = await res.json();
return {
props: {
user: data
}
};
}
}) satisfies PageServerLoad;

View file

@ -0,0 +1,12 @@
<script lang="ts">
import type { PageData } from './$types';
export let data: PageData;
const user = data.props.user;
console.log(user);
</script>
<h1>{user.first_name} {user.last_name}</h1>
<p>{user.username}</p>
<p>{user.is_staff ? 'Admin' : 'User'}</p>