+
+
{group.name}
+
+ {group.playerCount} membres
+
-
+ {#if group.playerCount < limit}
{#if $page.data.user?.groups.some((g) => g.name === group.name)}
{/if}
-
+ {/if}
{/each}
diff --git a/src/routes/(app)/chapters/[chapterId]/groups/new/+page.server.ts b/src/routes/(app)/chapters/[chapterId]/groups/new/+page.server.ts
index 7db9b8a..bfe3c0d 100644
--- a/src/routes/(app)/chapters/[chapterId]/groups/new/+page.server.ts
+++ b/src/routes/(app)/chapters/[chapterId]/groups/new/+page.server.ts
@@ -1,15 +1,16 @@
+import { API_URL } from "$env/static/private";
import { fail, redirect, type Actions } from "@sveltejs/kit";
import type { PageServerLoad } from "./$types";
import { superValidate } from "sveltekit-superforms";
import { zod } from "sveltekit-superforms/adapters";
-import { API_URL } from "$env/static/private";
+import { handleRedirect } from "$lib/utils";
import { groupSchema } from "$lib/validations/group";
-export const load: PageServerLoad = async ({ params: { chapterId }, locals: { user } }) => {
+export const load: PageServerLoad = async ({ url, params: { chapterId }, locals: { user } }) => {
- if (!user) redirect(302, '/login');
+ if (!user) redirect(302, handleRedirect('login', url));
if (user.groups.find(g => g.chapter === parseInt(chapterId))) {
redirect(302, `/chapters/${chapterId}/groups`);
@@ -24,14 +25,12 @@ export const load: PageServerLoad = async ({ params: { chapterId }, locals: { us
};
export const actions: Actions = {
- default: async ({ locals: { user }, fetch, request, cookies, params: { chapterId } }) => {
+ default: async ({ url, locals: { user }, fetch, request, params: { chapterId } }) => {
- if (!user) redirect(302, '/login');
+ if (!user) redirect(302, handleRedirect('login', url));
if (!chapterId) redirect(302, '/chapters');
- const session = cookies.get('session');
-
const form = await superValidate(request, zod(groupSchema));
if (!form.valid) {
@@ -40,9 +39,6 @@ export const actions: Actions = {
const res = await fetch(`${API_URL}/groupCreate`, {
method: 'POST',
- headers: {
- Authorization: `Bearer ${session}`
- },
body: JSON.stringify({
...form.data,
chapter: parseInt(chapterId)
diff --git a/src/routes/(app)/chapters/[chapterId]/leaderboard/+page.server.ts b/src/routes/(app)/chapters/[chapterId]/leaderboard/+page.server.ts
index 15f9863..d328875 100644
--- a/src/routes/(app)/chapters/[chapterId]/leaderboard/+page.server.ts
+++ b/src/routes/(app)/chapters/[chapterId]/leaderboard/+page.server.ts
@@ -1,22 +1,17 @@
import { API_URL } from '$env/static/private';
-import type { PageServerLoad } from './$types';
import { redirect } from '@sveltejs/kit';
+import type { PageServerLoad } from './$types';
import type { LeaderboardEvent } from '$lib/types';
+import { handleRedirect } from '$lib/utils';
-export const load: PageServerLoad = async ({ locals: { user }, fetch, cookies, params: { chapterId } }) => {
+export const load: PageServerLoad = async ({ url, locals: { user }, fetch, params: { chapterId } }) => {
- if (!user) redirect(302, '/login');
+ if (!user) redirect(302, handleRedirect('login', url));
if (!chapterId) redirect(302, '/');
- const session = cookies.get('session');
-
- const res = await fetch(`${API_URL}/leaderboard/${chapterId}`, {
- headers: {
- Authorization: `Bearer ${session}`
- }
- });
+ const res = await fetch(`${API_URL}/leaderboard/${chapterId}`);
if (!res.ok) return {
leaderboard: []
diff --git a/src/routes/(app)/chapters/[chapterId]/puzzle/+page.server.ts b/src/routes/(app)/chapters/[chapterId]/puzzle/+page.server.ts
index 1a4e06b..5d22be6 100644
--- a/src/routes/(app)/chapters/[chapterId]/puzzle/+page.server.ts
+++ b/src/routes/(app)/chapters/[chapterId]/puzzle/+page.server.ts
@@ -2,7 +2,9 @@ import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
-export const load = (async ({ locals: { user }, params: { chapterId } }) => {
- if (!user) redirect(302, '/login');
+import { handleRedirect } from '$lib/utils';
+
+export const load = (async ({ url, locals: { user }, params: { chapterId } }) => {
+ if (!user) redirect(302, handleRedirect('login', url));
redirect(302, chapterId ? `/chapters/${chapterId}` : `/chapters`);
}) satisfies PageServerLoad;
diff --git a/src/routes/(app)/chapters/[chapterId]/puzzle/[puzzleId]/+page.server.ts b/src/routes/(app)/chapters/[chapterId]/puzzle/[puzzleId]/+page.server.ts
index 78d7189..d5983df 100644
--- a/src/routes/(app)/chapters/[chapterId]/puzzle/[puzzleId]/+page.server.ts
+++ b/src/routes/(app)/chapters/[chapterId]/puzzle/[puzzleId]/+page.server.ts
@@ -1,13 +1,14 @@
import { API_URL } from '$env/static/private';
import { error, redirect, type Actions } from '@sveltejs/kit';
-import type { PageServerLoad } from './$types';
import { compile } from 'mdsvex';
+import type { PageServerLoad } from './$types';
import type Puzzle from '$lib/components/puzzle.svelte';
import type { Chapter } from '$lib/types';
+import { handleRedirect } from '$lib/utils';
-export const load = (async ({ locals: { user }, fetch, cookies, params: { chapterId, puzzleId } }) => {
- if (!user) redirect(302, '/login');
+export const load = (async ({ url, locals: { user }, fetch, cookies, params: { chapterId, puzzleId } }) => {
+ if (!user) redirect(302, handleRedirect('login', url));
const session = cookies.get('session');
@@ -15,11 +16,7 @@ export const load = (async ({ locals: { user }, fetch, cookies, params: { chapte
redirect(302, `/chapters/${chapterId}`);
}
- let res = await fetch(`${API_URL}/chapter/${chapterId}`, {
- headers: {
- Authorization: `Bearer ${session}`
- }
- });
+ let res = await fetch(`${API_URL}/chapter/${chapterId}`);
if (!res.ok) {
redirect(302, `/chapters`);
@@ -38,20 +35,22 @@ export const load = (async ({ locals: { user }, fetch, cookies, params: { chapte
redirect(302, `/chapters/${chapterId}`);
}
- res = await fetch(`${API_URL}/puzzle/${puzzleId}`, {
- headers: {
- Authorization: `Bearer ${session}`
- }
- });
+ res = await fetch(`${API_URL}/puzzle/${puzzleId}`);
if (!res.ok) {
- error(404, 'Puzzle not found');
+ error(404, {
+ errorId: 'puzzle_not_found',
+ message: 'Puzzle not found'
+ });
}
const puzzle: Puzzle = await res.json();
if (!puzzle) {
- error(404, 'Puzzle not found');
+ error(404, {
+ errorId: 'puzzle_not_found',
+ message: 'Puzzle not found'
+ });
}
const content = await compile(puzzle.content);
diff --git a/src/routes/(app)/groups/+page.svelte b/src/routes/(app)/groups/+page.svelte
deleted file mode 100644
index 42f2102..0000000
--- a/src/routes/(app)/groups/+page.svelte
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-TODO
diff --git a/src/routes/(app)/leaderboard/+page.server.ts b/src/routes/(app)/leaderboard/+page.server.ts
index 5d0267a..3b1b37d 100644
--- a/src/routes/(app)/leaderboard/+page.server.ts
+++ b/src/routes/(app)/leaderboard/+page.server.ts
@@ -4,18 +4,13 @@ import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import type { Leaderboard } from '$lib/types';
+import { handleRedirect } from '$lib/utils';
-export const load = (async ({ locals: { user }, fetch, cookies }) => {
+export const load = (async ({ url, locals: { user }, fetch }) => {
- if (!user) redirect(302, '/login');
+ if (!user) redirect(302, handleRedirect('login', url));
- const session = cookies.get('session');
-
- const res = await fetch(`${API_URL}/leaderboard`, {
- headers: {
- Authorization: `Bearer ${session}`
- }
- });
+ const res = await fetch(`${API_URL}/leaderboard`);
if (!res.ok) {
return {
diff --git a/src/routes/(app)/settings/+layout.svelte b/src/routes/(app)/settings/+layout.svelte
index a858d9c..9d993e3 100644
--- a/src/routes/(app)/settings/+layout.svelte
+++ b/src/routes/(app)/settings/+layout.svelte
@@ -1,5 +1,7 @@
-
-
-
-
diff --git a/src/routes/(auth)/login/+page.server.ts b/src/routes/(auth)/login/+page.server.ts
index 20d2de9..88dfd07 100644
--- a/src/routes/(auth)/login/+page.server.ts
+++ b/src/routes/(auth)/login/+page.server.ts
@@ -21,7 +21,7 @@ export const load: PageServerLoad = async ({ locals: { user } }) => {
};
export const actions: Actions = {
- default: async ({ request, cookies, fetch }) => {
+ default: async ({ request, cookies, fetch, url: { searchParams } }) => {
const form = await superValidate(request, zod(loginSchema));
@@ -52,6 +52,11 @@ export const actions: Actions = {
sameSite: 'strict',
});
+ const redirectTo = searchParams.get('redirectTo');
+
+ if (redirectTo)
+ redirect(302, `/${redirectTo.slice(1)}`);
+
redirect(302, '/');
}
};
diff --git a/src/routes/(auth)/register/+page.server.ts b/src/routes/(auth)/register/+page.server.ts
index 776fc4e..bee7810 100644
--- a/src/routes/(auth)/register/+page.server.ts
+++ b/src/routes/(auth)/register/+page.server.ts
@@ -53,7 +53,7 @@ export const actions: Actions = {
form
};
},
- confirmation: async ({ request, cookies }) => {
+ confirmation: async ({ request, cookies, url: { searchParams } }) => {
const form = await superValidate(request, zod(registerConfirmationSchema));
if (!form.valid) {
@@ -93,6 +93,11 @@ export const actions: Actions = {
sameSite: 'strict',
});
+ const redirectTo = searchParams.get('redirectTo');
+
+ if (redirectTo)
+ redirect(302, `/${redirectTo.slice(1)}`);
+
redirect(302, '/');
- },
+ }
}
diff --git a/src/routes/(auth)/register/+page.svelte b/src/routes/(auth)/register/+page.svelte
index 571c982..8f31588 100644
--- a/src/routes/(auth)/register/+page.svelte
+++ b/src/routes/(auth)/register/+page.svelte
@@ -11,7 +11,6 @@
import Input from '$lib/components/ui/input/input.svelte';
import { registerConfirmationSchema, registerSchema } from '$lib/validations/auth';
- import { enhance } from '$app/forms';
export let data: PageData;
diff --git a/src/routes/+error.svelte b/src/routes/+error.svelte
new file mode 100644
index 0000000..0a79ca7
--- /dev/null
+++ b/src/routes/+error.svelte
@@ -0,0 +1,14 @@
+
+
+
+
+
Oops!
+
Apparement tu as navigué en eau trouble...
+
+
{$page.error?.errorId}
+
+
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index c627082..903425f 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -2,8 +2,11 @@
import '../app.css';
import { Metadata } from '$lib/components';
+ import { Toaster } from '$lib/components/ui/sonner';
+
+