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:
parent
a70b1f2818
commit
7d228b302b
6 changed files with 135 additions and 2 deletions
29
frontend/src/routes/user/[uuid]/+page.server.ts
Normal file
29
frontend/src/routes/user/[uuid]/+page.server.ts
Normal 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;
|
12
frontend/src/routes/user/[uuid]/+page.svelte
Normal file
12
frontend/src/routes/user/[uuid]/+page.svelte
Normal 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>
|
Loading…
Add table
Add a link
Reference in a new issue