coyotte508 HF staff commited on
Commit
36f8d04
1 Parent(s): bd9595b

✨ Add account page

Browse files
src/routes/+layout.server.ts CHANGED
@@ -17,13 +17,23 @@ export const load: LayoutServerLoad = async (input) => {
17
  return {
18
  pageData,
19
  pictures: pics,
20
- user: !!input.locals.user
 
 
 
 
 
21
  };
22
  }
23
 
24
  return {
25
  pageData: null,
26
  pictures: [] as Picture[],
27
- user: !!input.locals.user
 
 
 
 
 
28
  };
29
  };
 
17
  return {
18
  pageData,
19
  pictures: pics,
20
+ user: input.locals.user
21
+ ? {
22
+ email: input.locals.user.email,
23
+ admin: input.locals.user.authority === 'admin'
24
+ }
25
+ : null
26
  };
27
  }
28
 
29
  return {
30
  pageData: null,
31
  pictures: [] as Picture[],
32
+ user: input.locals.user
33
+ ? {
34
+ email: input.locals.user.email,
35
+ admin: input.locals.user.authority === 'admin'
36
+ }
37
+ : null
38
  };
39
  };
src/routes/compte/+page.server.ts ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import { redirect } from '@sveltejs/kit';
2
+ import type { ServerLoad } from './$types';
3
+
4
+ export const load: ServerLoad = (event) => {
5
+ if (!event.locals.user) {
6
+ throw redirect(303, `/connexion?suivant=${encodeURIComponent(event.url.href)}`);
7
+ }
8
+
9
+ return {};
10
+ };
src/routes/compte/+page.svelte ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import Container from '$lib/components/Container.svelte';
3
+ import type { PageData } from './$types';
4
+
5
+ export let data: PageData;
6
+ $: user = data.user!;
7
+ </script>
8
+
9
+ <Container>
10
+ <p>
11
+ Bienvenue, {user.email}!
12
+ </p>
13
+
14
+ {#if user.admin}
15
+ <p><a href="/admin" class="link">Admin</a></p>
16
+ {/if}
17
+
18
+ <form
19
+ action="/deconnexion"
20
+ method="post"
21
+ class="text-sunray text-3xl inline-block cursor-pointer"
22
+ >
23
+ <input type="submit" value="Déconnexion" class="cursor-pointer btn" />
24
+ </form>
25
+ </Container>
src/routes/connexion/+layout.server.ts CHANGED
@@ -3,7 +3,7 @@ import type { LayoutServerLoad } from './$types';
3
 
4
  export const load: LayoutServerLoad = (event) => {
5
  if (event.locals.user) {
6
- throw redirect(302, '/');
7
  }
8
 
9
  return {};
 
3
 
4
  export const load: LayoutServerLoad = (event) => {
5
  if (event.locals.user) {
6
+ throw redirect(303, '/');
7
  }
8
 
9
  return {};
src/routes/deconnexion/+page.server.ts CHANGED
@@ -3,6 +3,7 @@ import type { Actions } from './$types';
3
 
4
  export const actions: Actions = {
5
  default: async (event) => {
 
6
  throw redirect(303, event.request.headers.get('referer') ?? '/');
7
  }
8
  };
 
3
 
4
  export const actions: Actions = {
5
  default: async (event) => {
6
+ event.cookies.delete('bergereToken', { path: '/' });
7
  throw redirect(303, event.request.headers.get('referer') ?? '/');
8
  }
9
  };