2023-05-21 05:18:04 +00:00
|
|
|
<script lang="ts">
|
2023-07-31 05:24:33 +00:00
|
|
|
import { page } from '$app/stores';
|
2023-05-21 05:18:04 +00:00
|
|
|
import { superForm } from 'sveltekit-superforms/client';
|
2023-07-30 23:31:39 +00:00
|
|
|
import * as flashModule from 'sveltekit-flash-message/client';
|
2023-07-31 05:24:33 +00:00
|
|
|
import toast from 'svelte-french-toast';
|
2023-07-01 23:12:17 +00:00
|
|
|
import { AlertCircle } from "lucide-svelte";
|
2023-09-08 23:30:32 +00:00
|
|
|
import { signInSchema } from '$lib/config/zod-schemas.js';
|
|
|
|
|
import { Label } from '$components/ui/label';
|
|
|
|
|
import { Input } from '$components/ui/input';
|
|
|
|
|
import { Button } from '$components/ui/button';
|
|
|
|
|
import * as Alert from "$components/ui/alert";
|
2023-05-21 05:18:04 +00:00
|
|
|
|
|
|
|
|
export let data;
|
|
|
|
|
const { form, errors, enhance, delayed } = superForm(data.form, {
|
2023-07-30 23:31:39 +00:00
|
|
|
flashMessage: {
|
|
|
|
|
module: flashModule,
|
|
|
|
|
onError: ({ result, message }) => {
|
|
|
|
|
// Error handling for the flash message:
|
2023-07-31 05:24:33 +00:00
|
|
|
// - result is the ActionResult
|
|
|
|
|
// - message is the flash store (not the status message store)
|
|
|
|
|
const errorMessage = result.error.message
|
|
|
|
|
message.set({ type: 'error', message: errorMessage });
|
2023-07-30 23:31:39 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
syncFlashMessage: false,
|
2023-05-21 05:18:04 +00:00
|
|
|
taintedMessage: null,
|
2023-09-08 23:30:32 +00:00
|
|
|
validators: signInSchema,
|
2023-05-29 06:34:39 +00:00
|
|
|
validationMethod: 'oninput',
|
2023-05-21 05:18:04 +00:00
|
|
|
delayMs: 0,
|
|
|
|
|
});
|
2023-07-31 05:24:33 +00:00
|
|
|
|
|
|
|
|
const flash = flashModule.getFlash(page);
|
|
|
|
|
|
|
|
|
|
$: {
|
|
|
|
|
if ($flash) {
|
|
|
|
|
toast.error($flash.message, {
|
|
|
|
|
duration: 5000
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-21 05:18:04 +00:00
|
|
|
</script>
|
|
|
|
|
|
2023-09-08 23:30:32 +00:00
|
|
|
<svelte:head>
|
|
|
|
|
<title>Bored Game | Login</title>
|
|
|
|
|
</svelte:head>
|
|
|
|
|
|
|
|
|
|
<div class="login">
|
2023-09-12 00:29:15 +00:00
|
|
|
<form method="POST" use:enhance>
|
2023-09-11 22:15:53 +00:00
|
|
|
<h2
|
|
|
|
|
class="scroll-m-20 border-b pb-2 text-3xl font-semibold tracking-tight transition-colors first:mt-0"
|
|
|
|
|
>
|
|
|
|
|
Log into your account
|
|
|
|
|
</h2>
|
|
|
|
|
<Label for="username">Username</Label>
|
|
|
|
|
<Input type="text" id="username" name="username" placeholder="Username" autocomplete="username" data-invalid={$errors.username} bind:value={$form.username} required />
|
|
|
|
|
<Label for="password">Password</Label>
|
|
|
|
|
<Input type="password" id="password" name="password" placeholder="Password" autocomplete="password" data-invalid={$errors.password} bind:value={$form.password} required />
|
|
|
|
|
<Button type="submit">Login</Button>
|
2023-09-14 00:08:54 +00:00
|
|
|
{#if $errors._errors}
|
2023-09-08 23:30:32 +00:00
|
|
|
<Alert.Root variant="destructive">
|
2023-07-01 23:12:17 +00:00
|
|
|
<AlertCircle class="h-4 w-4" />
|
2023-09-08 23:30:32 +00:00
|
|
|
<Alert.Title>Error</Alert.Title>
|
|
|
|
|
<Alert.Description>
|
2023-07-01 23:12:17 +00:00
|
|
|
{$errors._errors}
|
2023-09-08 23:30:32 +00:00
|
|
|
</Alert.Description>
|
|
|
|
|
</Alert.Root>
|
2023-05-21 05:18:04 +00:00
|
|
|
{/if}
|
2023-09-11 22:15:53 +00:00
|
|
|
<p class="px-8 text-center text-sm text-muted-foreground">
|
|
|
|
|
By clicking continue, you agree to our
|
2023-09-14 00:08:54 +00:00
|
|
|
<a href="/terms" class="underline underline-offset-4 hover:text-primary">
|
|
|
|
|
Terms of Use
|
2023-09-11 22:15:53 +00:00
|
|
|
</a>
|
|
|
|
|
and
|
2023-09-14 00:08:54 +00:00
|
|
|
<a href="/privacy" class="underline underline-offset-4 hover:text-primary">
|
|
|
|
|
Privacy Policy
|
|
|
|
|
</a>.
|
2023-09-11 22:15:53 +00:00
|
|
|
</p>
|
2023-09-14 00:08:54 +00:00
|
|
|
</form>
|
2023-07-31 05:24:33 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<style lang="postcss">
|
2023-09-08 23:30:32 +00:00
|
|
|
.login {
|
2023-09-12 00:29:15 +00:00
|
|
|
display: flex;
|
|
|
|
|
margin-top: 1.5rem;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
justify-content: center;
|
2023-09-11 22:15:53 +00:00
|
|
|
width: 100%;
|
|
|
|
|
margin-right: auto;
|
2023-09-12 00:29:15 +00:00
|
|
|
margin-left: auto;
|
|
|
|
|
|
|
|
|
|
@media (min-width: 640px) {
|
|
|
|
|
width: 350px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
form {
|
|
|
|
|
display: grid;
|
|
|
|
|
gap: 0.5rem;
|
|
|
|
|
align-items: center;
|
|
|
|
|
max-width: 24rem;
|
|
|
|
|
}
|
2023-07-31 05:24:33 +00:00
|
|
|
}
|
|
|
|
|
</style>
|