Compare commits

...

3 commits

Author SHA1 Message Date
glazk0
8ba01a5019
feat: Dockerfile improvement 2024-02-19 22:06:20 +01:00
glazk0
f1889e0eab
fix: utils & register / confirmation issue 2024-02-19 22:06:12 +01:00
glazk0
0eabfa812f
chore: deps update 2024-02-19 22:05:22 +01:00
49 changed files with 1664 additions and 861 deletions

View file

@ -1,35 +1,37 @@
# Base Stage
FROM node:21-slim AS base
FROM node:18-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN npm i -g pnpm
FROM base AS dependencies
RUN corepack enable
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
# Dependencies Stage for Production
FROM base AS deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
# Build Stage
FROM base AS build
WORKDIR /app
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
COPY . .
COPY --from=dependencies /app/node_modules ./node_modules
RUN pnpm build
RUN pnpm prune --prod
RUN pnpm run build
# Deploy Stage
FROM base AS deploy
WORKDIR /app
COPY --from=deps /app/node_modules /app/node_modules
COPY --from=build /app/build /app/build
COPY --from=build /app/build ./build
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/package.json ./package.json
# Run as non-root user
USER node
ARG PORT=3000

View file

@ -17,38 +17,38 @@
},
"dependencies": {
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"lucide-svelte": "^0.279.0",
"marked": "^7.0.5",
"svelte-boring-avatars": "^1.2.4",
"tailwind-merge": "^1.14.0"
"clsx": "^2.1.0",
"lucide-svelte": "^0.330.0",
"marked": "^12.0.0",
"svelte-boring-avatars": "^1.2.5",
"tailwind-merge": "^2.2.1"
},
"devDependencies": {
"@melt-ui/pp": "^0.1.4",
"@melt-ui/svelte": "^0.50.1",
"@playwright/test": "^1.40.0",
"@sveltejs/adapter-node": "^1.3.1",
"@sveltejs/kit": "^1.27.6",
"@types/marked": "^5.0.2",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"autoprefixer": "^10.4.16",
"eslint": "^8.54.0",
"eslint-config-prettier": "^8.10.0",
"@melt-ui/pp": "^0.3.0",
"@melt-ui/svelte": "^0.73.0",
"@playwright/test": "^1.41.2",
"@sveltejs/adapter-node": "^4.0.1",
"@sveltejs/kit": "^2.5.0",
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"autoprefixer": "^10.4.17",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.35.1",
"postcss": "^8.4.31",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.10.1",
"prettier-plugin-tailwindcss": "^0.4.1",
"svelte": "^4.2.7",
"svelte-check": "^3.6.1",
"postcss": "^8.4.35",
"prettier": "^3.2.5",
"prettier-plugin-svelte": "^3.1.2",
"prettier-plugin-tailwindcss": "^0.5.11",
"svelte": "^4.2.10",
"svelte-check": "^3.6.4",
"svelte-sequential-preprocessor": "^2.0.1",
"sveltekit-superforms": "^1.10.2",
"tailwindcss": "^3.3.5",
"sveltekit-superforms": "^2.1.0",
"tailwindcss": "^3.4.1",
"tslib": "^2.6.2",
"typescript": "^5.3.2",
"vite": "^4.5.0",
"vitest": "^0.32.4",
"typescript": "^5.3.3",
"vite": "^5.1.1",
"vitest": "^1.2.2",
"zod": "^3.22.4"
}
}

2071
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

View file

@ -80,10 +80,13 @@
@layer base {
* {
box-sizing: border-box;
scroll-behavior: smooth;
@apply border-border text-white;
}
body {
@apply text-foreground;
@apply text-foreground bg-gradient-to-b from-primary-800 to-primary-900;
}
}
@ -91,6 +94,7 @@
.console {
@apply relative top-0.5 inline-block;
}
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,

4
src/app.d.ts vendored
View file

@ -7,10 +7,10 @@ declare global {
namespace App {
// interface Error {}
interface Locals {
user?: User;
user: User | null;
}
interface PageData {
user?: User;
user: User | null;
}
// interface Platform {}
}

View file

@ -1,28 +1,6 @@
<!DOCTYPE html>
<html lang="fr" class="scroll-smooth bg-gradient-to-b from-primary-800 to-primary-900">
<html lang="fr">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/x-icon" href="%sveltekit.assets%/favicon.ico" />
<link
rel="apple-touch-icon"
sizes="180x180"
href="%sveltekit.assets%/assets/icons/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="%sveltekit.assets%/assets/icons/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="%sveltekit.assets%/assets/icons/favicon-16x16.png"
/>
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover" class="relative min-h-screen">

View file

@ -4,10 +4,14 @@ import { API_URL } from '$env/static/private';
import type { User } from '$lib/types';
export const handle = (async ({ event, resolve }) => {
export const handle: Handle = async ({ event, resolve }) => {
const session = event.cookies.get('session');
if (session) {
if (!session) {
event.locals.user = null;
return resolve(event);
}
const res = await fetch(`${API_URL}/player/`, {
headers: {
Authorization: `Bearer ${session}`
@ -18,10 +22,9 @@ export const handle = (async ({ event, resolve }) => {
const user = (await res.json()) as User;
event.locals.user = user;
} else {
event.locals.user = undefined;
event.cookies.delete('session');
}
event.locals.user = null;
event.cookies.delete('session', { path: '/' });
}
return await resolve(event);
}) satisfies Handle;
return resolve(event);
};

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { cn } from '$lib/Utils';
import { cn } from '$lib/utils';
export let name: string;
export let src: string;

View file

@ -1,10 +1,10 @@
<script lang="ts">
import { cn } from '$lib/Utils';
import type { Chapter } from '$lib/types';
import { Trophy } from 'lucide-svelte';
import type { Chapter } from '$lib/types';
import { cn } from '$lib/utils';
import ChevronRight from './Icons/ChevronRight.svelte';
import Button from './ui/Button.svelte';
export let chapter: Chapter;
</script>

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { cn } from '$lib';
import { cn } from '$lib/utils';
let className: string | undefined | null = undefined;

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { cn } from '$lib';
import { cn } from '$lib/utils';
let className: string | undefined | null = undefined;

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { cn } from '$lib';
import { cn } from '$lib/utils';
let className: string | undefined | null = undefined;

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { cn } from '$lib';
import { cn } from '$lib/utils';
let className: string | undefined | null = undefined;

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { cn } from '$lib';
import { cn } from '$lib/utils';
let className: string | undefined | null = undefined;

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { cn } from '$lib';
import { cn } from '$lib/utils';
let className: string | undefined | null = undefined;

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { cn } from '$lib';
import { cn } from '$lib/utils';
let className: string | undefined | null = undefined;

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { cn } from '$lib';
import { cn } from '$lib/utils';
let className: string | undefined | null = undefined;

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { cn } from '$lib';
import { cn } from '$lib/utils';
let className: string | undefined | null = undefined;

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { cn } from '$lib';
import { cn } from '$lib/utils';
let className: string | undefined | null = undefined;

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { cn } from '$lib';
import { cn } from '$lib/utils';
let className: string | undefined | null = undefined;

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { cn } from '$lib';
import { cn } from '$lib/utils';
let className: string | undefined | null = undefined;

View file

@ -0,0 +1,49 @@
<script lang="ts">
import { page } from '$app/stores';
import { siteConfig } from '$lib/config/site';
</script>
<svelte:head>
{#key $page.url.pathname}
<title>{siteConfig.title}</title>
<meta name="title" content={siteConfig.title} />
<meta name="description" content={siteConfig.description} />
<meta name="keywords" content={siteConfig.keywords.join(',')} />
<meta name="author" content={siteConfig.author} />
<meta name="theme-color" content={siteConfig.themeColor} />
<meta name="robots" content="index,follow" />
<meta itemprop="name" content={siteConfig.title} />
<meta itemprop="description" content={siteConfig.description} />
<meta itemprop="image" content={siteConfig.imageUrl} />
<meta property="og:site_name" content={siteConfig.name} />
<meta property="og:title" content={siteConfig.title} />
<meta property="og:description" content={siteConfig.description} />
<meta property="og:type" content="website" />
<meta property="og:url" content={siteConfig.url + $page.url.pathname} />
<meta property="og:image" content={siteConfig.imageUrl} />
<meta property="og:image:alt" content={siteConfig.title} />
<meta property="og:locale" content={siteConfig.locale} />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content={siteConfig.url} />
<meta name="twitter:title" content={siteConfig.title} />
<meta name="twitter:description" content={siteConfig.description} />
<meta name="twitter:image" content={siteConfig.imageUrl} />
<meta name="twitter:image:alt" content={siteConfig.title} />
<meta name="twitter:creator" content={siteConfig.twitter.creator} />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="/assets/icons/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/assets/icons/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/assets/icons/favicon-16x16.png" />
{/key}
</svelte:head>

View file

@ -1,6 +1,6 @@
<script lang="ts">
import { page } from '$app/stores';
import { cn } from '$lib/Utils';
import { cn } from '$lib/utils';
import type { Puzzle } from '$lib/types';
import ChevronRight from './Icons/ChevronRight.svelte';

View file

@ -1,7 +1,7 @@
<script lang="ts">
import { page } from '$app/stores';
import { cn } from '$lib/Utils';
import { cn } from '$lib/utils';
import Badge from '$lib/components/Icons/Badge.svelte';
import Code from '$lib/components/Icons/Code.svelte';

View file

@ -2,9 +2,7 @@
import type { HTMLAnchorAttributes, HTMLButtonAttributes } from 'svelte/elements';
import { type VariantProps, cva } from 'class-variance-authority';
import { cn } from '$lib';
// TODO: Remove this
import { cn } from '$lib/utils';
export const buttonVariants = cva(
'inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',

View file

@ -1,7 +1,7 @@
<script lang="ts">
import type { HTMLInputAttributes } from 'svelte/elements';
import { cn } from '$lib';
import { cn } from '$lib/utils';
type FormInputEvent<T extends Event = Event> = T & {
currentTarget: EventTarget & HTMLInputElement;

16
src/lib/config/site.ts Normal file
View file

@ -0,0 +1,16 @@
export const siteConfig = {
name: 'Peer-at Code',
url: 'https://app.peerat.dev',
title: 'Peer-at Code',
description: 'Apprendre la programmation et la cybersécurité en s\'amusant.',
imageUrl: 'https://my-site.com/images/og-image.jpg',
keywords: ['peerat', 'code', 'cybersecurite', 'programmation', 'apprendre en s\'amusant'],
author: 'peerat',
locale: 'fr',
twitter: {
creator: '@peerat'
},
themeColor: '#110F15'
};
export type SiteConfig = typeof siteConfig;

View file

@ -1 +0,0 @@
export * from './Utils';

View file

@ -1 +1 @@
export * from './Database';
export * from './database';

View file

@ -1,6 +1,6 @@
import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) {
export const cn = (...inputs: ClassValue[]) => {
return twMerge(clsx(inputs));
}

View file

@ -1,43 +1,14 @@
<script lang="ts">
import '../app.css';
import { page } from '$app/stores';
import Metadata from '$lib/components/Metadata.svelte';
import Toaster from '$lib/components/Toaster.svelte';
$: origin = $page.url.origin;
$: domain = $page.url.hostname;
</script>
<Metadata />
<svelte:head>
<title>Peer-at Code</title>
<meta name="title" content="Peer-at Code" />
<meta name="description" content="Apprendre la programmation et la cybersécurité en s'amusant." />
<meta name="theme-color" content="#110F15" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="French" />
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website" />
<meta property="og:url" content={origin} />
<meta property="og:title" content="Peer-at Code" />
<meta
property="og:description"
content="Apprendre la programmation et la cybersécurité en s'amusant."
/>
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content={origin} />
<meta property="twitter:title" content="Peer-at Code" />
<meta
property="twitter:description"
content="Apprendre la programmation et la cybersécurité en s'amusant."
/>
<script defer data-domain={domain} src="https://plosibl.peerat.dev/js/script.js"></script>
<script defer data-domain="app.peerat.dev" src="https://plosibl.peerat.dev/js/script.js"></script>
</svelte:head>
<Toaster />

View file

@ -2,6 +2,6 @@ import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
export const load = (async ({ locals: { user } }) => {
if (user) throw redirect(303, '/dashboard');
throw redirect(303, '/sign-in');
if (user) redirect(303, '/dashboard');
redirect(303, '/sign-in');
}) satisfies PageServerLoad;

View file

@ -1,2 +0,0 @@
<script lang="ts">
</script>

View file

@ -2,5 +2,5 @@ import { redirect, type ServerLoad } from '@sveltejs/kit';
export const load: ServerLoad = async ({ locals: { user }, parent }) => {
await parent();
if (!user) throw redirect(303, '/sign-in');
if (!user) redirect(303, '/sign-in');
};

View file

@ -17,13 +17,13 @@ export const load = (async ({ parent, fetch, cookies, params: { chapterId } }) =
});
if (!res.ok) {
throw redirect(302, '/dashboard/chapters');
redirect(302, '/dashboard/chapters');
}
const chapter = (await res.json()) as Chapter;
if (!chapter || !chapter.show) {
throw redirect(302, '/dashboard/chapters');
redirect(302, '/dashboard/chapters');
}
return {

View file

@ -4,5 +4,5 @@ import type { PageServerLoad } from './$types';
export const load = (async ({ parent, params: { chapterId } }) => {
await parent();
throw redirect(303, chapterId ? `/dashboard/chapters/${chapterId}` : `/dashboard/chapters`);
redirect(303, chapterId ? `/dashboard/chapters/${chapterId}` : `/dashboard/chapters`);
}) satisfies PageServerLoad;

View file

@ -11,7 +11,7 @@ export const load = (async ({ parent, fetch, cookies, params: { chapterId, puzzl
const session = cookies.get('session');
if (isNaN(parseInt(puzzleId))) {
throw redirect(303, `/dashboard/chapters/${chapterId}`);
redirect(303, `/dashboard/chapters/${chapterId}`);
}
let res = await fetch(`${API_URL}/chapter/${chapterId}`, {
@ -21,20 +21,20 @@ export const load = (async ({ parent, fetch, cookies, params: { chapterId, puzzl
});
if (!res.ok) {
throw redirect(303, `/dashboard/chapters`);
redirect(303, `/dashboard/chapters`);
}
const chapter = (await res.json()) as Chapter;
if (!chapter || !chapter.show) {
throw redirect(303, `/dashboard/chapters`);
redirect(303, `/dashboard/chapters`);
}
if (
!chapter.puzzles.some((puzzle) => puzzle.id === parseInt(puzzleId)) ||
!chapter.puzzles.find((puzzle) => puzzle.id === parseInt(puzzleId))?.show
) {
throw redirect(303, `/dashboard/chapters/${chapterId}`);
redirect(303, `/dashboard/chapters/${chapterId}`);
}
res = await fetch(`${API_URL}/puzzle/${puzzleId}`, {
@ -44,13 +44,13 @@ export const load = (async ({ parent, fetch, cookies, params: { chapterId, puzzl
});
if (!res.ok) {
throw error(404, 'Puzzle not found');
error(404, 'Puzzle not found');
}
const puzzle = await res.json();
if (!puzzle) {
throw error(404, 'Puzzle not found');
error(404, 'Puzzle not found');
}
return {
@ -62,6 +62,6 @@ export const load = (async ({ parent, fetch, cookies, params: { chapterId, puzzl
export const actions = {
default: async ({ params }) => {
throw redirect(303, `/dashboard/chapters/${params.chapterId}/puzzle/${params.puzzleId}`);
redirect(303, `/dashboard/chapters/${params.chapterId}/puzzle/${params.puzzleId}`);
}
} satisfies Actions;

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { cn } from '$lib';
import { cn } from '$lib/utils';
import type { PageData } from './$types';
export let data: PageData;

View file

@ -10,7 +10,7 @@ export const load = (async ({ parent, fetch, cookies, params: { chapterId } }) =
await parent();
if (!chapterId) {
throw redirect(303, '/dashboard');
redirect(303, '/dashboard');
}
const session = cookies.get('session');
@ -22,13 +22,13 @@ export const load = (async ({ parent, fetch, cookies, params: { chapterId } }) =
});
if (!res.ok) {
throw redirect(303, '/dashboard');
redirect(303, '/dashboard');
}
const leaderboard = (await res.json()) as LeaderboardEvent;
if (!leaderboard || !leaderboard.groups.length) {
throw redirect(303, '/dashboard');
redirect(303, '/dashboard');
}
return {

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { cn } from '$lib';
import { cn } from '$lib/utils';
import type { PageData } from './$types';
export let data: PageData;

View file

@ -7,7 +7,7 @@
import Button from '$lib/components/ui/Button.svelte';
import Input from '$lib/components/ui/Input.svelte';
import plausible from '$lib/stores/Plausible';
import plausible from '$lib/stores/plausible';
import { addToast } from '$lib/components/Toaster.svelte';
export let data: PageData;

View file

@ -6,6 +6,7 @@ import type { PageServerLoad } from './$types';
import { superValidate } from 'sveltekit-superforms/server';
import { z } from 'zod';
import { zod } from 'sveltekit-superforms/adapters';
const forgotSchema = z.object({
email: z
@ -43,9 +44,9 @@ const confirmationSchema = z.object({
});
export const load = (async ({ locals: { user } }) => {
if (user) throw redirect(303, '/dashboard');
if (user) redirect(303, '/dashboard');
const form = await superValidate(forgotSchema);
const form = await superValidate(zod(forgotSchema));
return {
form
@ -54,7 +55,7 @@ export const load = (async ({ locals: { user } }) => {
export const actions = {
forgot: async ({ request, cookies }) => {
const form = await superValidate(request, forgotSchema);
const form = await superValidate(request, zod(forgotSchema));
if (!form.valid) {
return fail(400, { form });
@ -77,8 +78,6 @@ export const actions = {
body: JSON.stringify(data)
});
console.log(res);
if (res.ok) {
const token = res.headers.get('Authorization')?.split('Bearer ')[1];
@ -87,21 +86,21 @@ export const actions = {
path: '/'
});
throw redirect(303, '/dashboard');
redirect(303, '/dashboard');
}
return {
form
};
}
form.errors.passwd = ['Code invalide ou expiré'];
form.errors.code = ['Code invalide ou expiré'];
return fail(400, {
form
});
},
confirmation: async ({ request, cookies }) => {
const form = await superValidate(request, confirmationSchema);
const form = await superValidate(request, zod(confirmationSchema));
if (!form.valid) {
return fail(400, { form });
@ -125,7 +124,7 @@ export const actions = {
path: '/'
});
throw redirect(303, '/dashboard');
redirect(303, '/dashboard');
}
form.errors.code = [`Une erreur s'est produite (${res.status} ${res.statusText})`];

View file

@ -30,7 +30,6 @@
});
break;
}
submitting = false;
}
});
@ -58,7 +57,9 @@
type="email"
placeholder="philipzcwbarlow@peerat.dev"
autocomplete="off"
autocorrect="off"
required
aria-invalid={$errors.email ? 'true' : undefined}
/>
{#if $errors.email}<span class="text-sm text-red-500">{$errors.email}</span>{/if}
@ -69,12 +70,26 @@
duration: 300
}}
>
<label for="passwd"> Mot de passe </label>
<Input name="passwd" placeholder="************" type="password" />
<label for="passwd"> Nouveau Mot de passe </label>
<Input
bind:value={$form.passwd}
name="passwd"
placeholder="************"
type="password"
required
aria-invalid={$errors.passwd ? 'true' : undefined}
/>
{#if $errors.passwd}<span class="text-sm text-red-500">{$errors.passwd}</span>{/if}
<label for="code"> Code </label>
<Input name="code" placeholder="1234" type="text" />
<Input
bind:value={$form.code}
name="code"
placeholder="1234"
type="text"
required
aria-invalid={$errors.code ? 'true' : undefined}
/>
{#if $errors.code}<span class="text-sm text-red-500">{$errors.code}</span>{/if}
</div>
{/if}
@ -92,9 +107,9 @@
</li>
{#if confirmation}
<li>
<button formaction="?/register" class="text-highlight-secondary hover:text-brand"
>Pas reçu ?</button
>
<button formaction="?/register" class="text-highlight-secondary hover:text-brand">
Renvoyer le code
</button>
</li>
{/if}
</ul>

View file

@ -9,5 +9,5 @@ export const load: ServerLoad = async ({ cookies, locals }) => {
locals.user = undefined;
throw redirect(303, '/');
redirect(303, '/');
};

View file

@ -1,30 +1,32 @@
import { API_URL } from '$env/static/private';
import { redirect, type Actions, fail } from '@sveltejs/kit';
import { fail, redirect, type Actions } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { zod } from 'sveltekit-superforms/adapters';
import { superValidate } from 'sveltekit-superforms/server';
import { z } from 'zod';
const schema = z.object({
pseudo: z.string().trim(),
passwd: z.string()
});
export const load = (async ({ locals: { user } }) => {
if (user) throw redirect(303, '/dashboard');
if (user) redirect(303, '/dashboard');
const form = await superValidate(schema);
const form = await superValidate(zod(schema));
return {
form
};
}) satisfies PageServerLoad;
const schema = z.object({
pseudo: z.string().trim(),
passwd: z.string()
});
export const actions = {
default: async ({ request, cookies }) => {
const form = await superValidate(request, schema);
const form = await superValidate(request, zod(schema));
if (!form.valid) {
return fail(400, { form });
@ -40,7 +42,12 @@ export const actions = {
if (res.ok) {
const token = res.headers.get('Authorization')?.split(' ')[1];
if (!token) throw new Error('No token found');
if (!token) {
form.errors.passwd = ["Une erreur est survenue, veuillez réessayer plus tard"];
return fail(500, { form });
}
cookies.set('session', token, {
path: '/'

View file

@ -6,6 +6,7 @@ import type { PageServerLoad } from './$types';
import { superValidate } from 'sveltekit-superforms/server';
import { z } from 'zod';
import { zod } from 'sveltekit-superforms/adapters';
const registerSchema = z.object({
email: z
@ -50,9 +51,9 @@ const confirmationSchema = z.object({
});
export const load = (async ({ locals: { user } }) => {
if (user) throw redirect(303, '/dashboard');
if (user) redirect(303, '/dashboard');
const form = await superValidate(registerSchema);
const form = await superValidate(zod(registerSchema));
return {
form
@ -61,7 +62,7 @@ export const load = (async ({ locals: { user } }) => {
export const actions = {
register: async ({ request }) => {
const form = await superValidate(request, registerSchema);
const form = await superValidate(request, zod(registerSchema));
if (!form.valid) {
return fail(400, { form });
@ -99,7 +100,7 @@ export const actions = {
});
},
confirmation: async ({ request, cookies }) => {
const form = await superValidate(request, confirmationSchema);
const form = await superValidate(request, zod(confirmationSchema));
if (!form.valid) {
return fail(400, { form });

View file

@ -1,13 +1,13 @@
<script lang="ts">
import { Loader2 } from 'lucide-svelte';
import { fade } from 'svelte/transition';
import { superForm } from 'sveltekit-superforms/client';
import { Loader2 } from 'lucide-svelte';
import type { PageData, Snapshot } from './$types';
import { addToast } from '$lib/components/Toaster.svelte';
import Button from '$lib/components/ui/Button.svelte';
import Input from '$lib/components/ui/Input.svelte';
import { addToast } from '$lib/components/Toaster.svelte';
export let data: PageData;
@ -63,6 +63,7 @@
type="email"
placeholder="philipzcwbarlow@peerat.dev"
autocomplete="off"
autocorrect="off"
required
aria-invalid={$errors.email ? 'true' : undefined}
/>
@ -75,6 +76,7 @@
type="text"
placeholder="Philip"
autocomplete="off"
autocorrect="off"
required
aria-invalid={$errors.firstname ? 'true' : undefined}
/>
@ -87,6 +89,7 @@
type="text"
placeholder="Barlow"
autocomplete="off"
autocorrect="off"
required
aria-invalid={$errors.lastname ? 'true' : undefined}
/>
@ -99,6 +102,7 @@
type="text"
placeholder="Cypher Wolf"
autocomplete="off"
autocorrect="off"
required
aria-invalid={$errors.pseudo ? 'true' : undefined}
/>
@ -116,6 +120,7 @@
name="passwd"
placeholder="************"
type="password"
required
aria-invalid={$errors.passwd ? 'true' : undefined}
/>
{#if $errors.passwd}<span class="text-sm text-red-500">{$errors.passwd}</span>{/if}
@ -125,6 +130,7 @@
name="code"
placeholder="1234"
type="text"
required
aria-invalid={$errors.code ? 'true' : undefined}
/>
{#if $errors.code}<span class="text-sm text-red-500">{$errors.code}</span>{/if}

View file

@ -1,7 +1,8 @@
import { preprocessMeltUI } from '@melt-ui/pp';
import sequence from 'svelte-sequential-preprocessor';
import adapter from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/kit/vite';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import sequence from 'svelte-sequential-preprocessor';
/** @type {import('@sveltejs/kit').Config}*/
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors

View file

@ -5,5 +5,8 @@ export default defineConfig({
plugins: [sveltekit()],
test: {
include: ['src/**/*.{test,spec}.{js,ts}']
},
define: {
SUPERFORMS_LEGACY: true
}
});