mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Fixing auth routes.
This commit is contained in:
parent
9584c708cd
commit
c53e5ffdc0
7 changed files with 140 additions and 35 deletions
|
|
@ -1,8 +1,10 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { enhance } from '$app/forms';
|
||||||
import Profile from '../preferences/profile.svelte';
|
import Profile from '../preferences/profile.svelte';
|
||||||
import logo from './bored-game.png';
|
import logo from './bored-game.png';
|
||||||
|
|
||||||
export let user: any;
|
export let user: any;
|
||||||
|
console.log('User', user);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
|
|
@ -15,38 +17,26 @@
|
||||||
<nav>
|
<nav>
|
||||||
<a href="/collection" title="Go to your collection" data-sveltekit-preload-data>Collection</a>
|
<a href="/collection" title="Go to your collection" data-sveltekit-preload-data>Collection</a>
|
||||||
<a href="/wishlist" title="Go to your wishlist" data-sveltekit-preload-data>Wishlist</a>
|
<a href="/wishlist" title="Go to your wishlist" data-sveltekit-preload-data>Wishlist</a>
|
||||||
<Profile />
|
|
||||||
{#if user}
|
{#if user}
|
||||||
<li>
|
<form
|
||||||
<a href="/profile" on:click={drawerClose}>
|
use:enhance
|
||||||
<span><Contact2 /></span><span class="flex-auto">{i('profile')}</span></a
|
action="/auth/signout"
|
||||||
|
method="POST"
|
||||||
|
>
|
||||||
|
<button type="submit" class="btn"
|
||||||
|
><span>Sign out</span></button
|
||||||
>
|
>
|
||||||
</li>
|
</form>
|
||||||
<li>
|
|
||||||
<form
|
|
||||||
use:enhance
|
|
||||||
action="/auth/sign-out"
|
|
||||||
method="post"
|
|
||||||
on:click={drawerClose}
|
|
||||||
on:keydown={drawerClose}
|
|
||||||
>
|
|
||||||
<button type="submit" class="btn"
|
|
||||||
><span><LogOut /></span><span>{i('signout')}</span></button
|
|
||||||
>
|
|
||||||
</form>
|
|
||||||
</li>
|
|
||||||
{/if}
|
{/if}
|
||||||
{#if !user}
|
{#if !user}
|
||||||
<li>
|
<a href="/auth/signin">
|
||||||
<a href="/auth/sign-in" on:click={drawerClose}>
|
<span class="flex-auto">Sign In</span></a
|
||||||
<span><LogIn /></span><span class="flex-auto">{i('signin')}</span></a
|
>
|
||||||
>
|
<a href="/auth/signup">
|
||||||
</li>
|
<span class="flex-auto">Sign Up</span></a
|
||||||
<li>
|
>
|
||||||
<a href="/auth/sign-up" on:click={drawerClose}>
|
{/if}
|
||||||
<span><UserCircle2 /></span><span class="flex-auto">{i('signup')}</span></a
|
<Profile />
|
||||||
>
|
|
||||||
</li>
|
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
export let data: Validation<SearchSchema>;
|
export let data: Validation<SearchSchema>;
|
||||||
const { form, constraints, errors, enhance } = superForm(data, {
|
const { form, constraints, errors } = superForm(data, {
|
||||||
onSubmit: () => {
|
onSubmit: () => {
|
||||||
boredState.update((n) => ({ ...n, loading: true }));
|
boredState.update((n) => ({ ...n, loading: true }));
|
||||||
},
|
},
|
||||||
|
|
@ -145,7 +145,7 @@
|
||||||
<SuperDebug data={$form} />
|
<SuperDebug data={$form} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<form id="search-form" action="/search" method="GET" use:enhance>
|
<form id="search-form" action="/search" method="GET">
|
||||||
<div class="search">
|
<div class="search">
|
||||||
<fieldset class="text-search" aria-busy={submitting} disabled={submitting}>
|
<fieldset class="text-search" aria-busy={submitting} disabled={submitting}>
|
||||||
<label for="q">Search</label>
|
<label for="q">Search</label>
|
||||||
|
|
|
||||||
0
src/lib/components/signin.svelte
Normal file
0
src/lib/components/signin.svelte
Normal file
113
src/lib/components/signup.svelte
Normal file
113
src/lib/components/signup.svelte
Normal file
|
|
@ -0,0 +1,113 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import { superForm } from 'sveltekit-superforms/client';
|
||||||
|
//import SuperDebug from 'sveltekit-superforms/client/SuperDebug.svelte';
|
||||||
|
import { userSchema } from '$lib/config/zod-schemas';
|
||||||
|
export let data;
|
||||||
|
|
||||||
|
const signUpSchema = userSchema.pick({
|
||||||
|
firstName: true,
|
||||||
|
lastName: true,
|
||||||
|
username: true,
|
||||||
|
email: true,
|
||||||
|
password: true
|
||||||
|
});
|
||||||
|
|
||||||
|
const { form, errors, enhance, delayed } = superForm(data.form, {
|
||||||
|
taintedMessage: null,
|
||||||
|
validators: signUpSchema,
|
||||||
|
delayMs: 0
|
||||||
|
});
|
||||||
|
// $: termsValue = $form.terms as Writable<boolean>;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form method="POST" action="/auth/signup" use:enhance>
|
||||||
|
<h1>Signup user</h1>
|
||||||
|
<label class="label">
|
||||||
|
<span class="sr-only">First Name</span>
|
||||||
|
<input
|
||||||
|
id="firstName"
|
||||||
|
name="firstName"
|
||||||
|
type="text"
|
||||||
|
placeholder="First Name"
|
||||||
|
autocomplete="given-name"
|
||||||
|
data-invalid={$errors.firstName}
|
||||||
|
bind:value={$form.firstName}
|
||||||
|
class="input"
|
||||||
|
class:input-error={$errors.firstName}
|
||||||
|
/>
|
||||||
|
{#if $errors.firstName}
|
||||||
|
<small>{$errors.firstName}</small>
|
||||||
|
{/if}
|
||||||
|
</label>
|
||||||
|
<label class="label">
|
||||||
|
<span class="sr-only">Last Name</span>
|
||||||
|
<input
|
||||||
|
id="lastName"
|
||||||
|
name="lastName"
|
||||||
|
type="text"
|
||||||
|
placeholder="Last Name"
|
||||||
|
autocomplete="family-name"
|
||||||
|
data-invalid={$errors.lastName}
|
||||||
|
bind:value={$form.lastName}
|
||||||
|
class="input"
|
||||||
|
class:input-error={$errors.lastName}
|
||||||
|
/>
|
||||||
|
{#if $errors.lastName}
|
||||||
|
<small>{$errors.lastName}</small>
|
||||||
|
{/if}
|
||||||
|
</label>
|
||||||
|
<label class="label">
|
||||||
|
<span class="sr-only">Email</span>
|
||||||
|
<input
|
||||||
|
id="email"
|
||||||
|
name="email"
|
||||||
|
type="email"
|
||||||
|
placeholder="Email"
|
||||||
|
autocomplete="email"
|
||||||
|
data-invalid={$errors.email}
|
||||||
|
bind:value={$form.email}
|
||||||
|
class="input"
|
||||||
|
class:input-error={$errors.email}
|
||||||
|
/>
|
||||||
|
{#if $errors.email}
|
||||||
|
<small>{$errors.email}</small>
|
||||||
|
{/if}
|
||||||
|
</label>
|
||||||
|
<label class="label">
|
||||||
|
<span class="sr-only">Username</span>
|
||||||
|
<input
|
||||||
|
id="username"
|
||||||
|
name="username"
|
||||||
|
type="username"
|
||||||
|
placeholder="Username"
|
||||||
|
autocomplete="uername"
|
||||||
|
data-invalid={$errors.username}
|
||||||
|
bind:value={$form.username}
|
||||||
|
class="input"
|
||||||
|
class:input-error={$errors.username}
|
||||||
|
/>
|
||||||
|
{#if $errors.username}
|
||||||
|
<small>{$errors.username}</small>
|
||||||
|
{/if}
|
||||||
|
</label>
|
||||||
|
<label class="label">
|
||||||
|
<span class="sr-only">password</span>
|
||||||
|
<input
|
||||||
|
id="password"
|
||||||
|
name="password"
|
||||||
|
type="password"
|
||||||
|
placeholder="password"
|
||||||
|
data-invalid={$errors.password}
|
||||||
|
bind:value={$form.password}
|
||||||
|
class="input"
|
||||||
|
class:input-error={$errors.password}
|
||||||
|
/>
|
||||||
|
{#if $errors.password}
|
||||||
|
<small>{$errors.password}</small>
|
||||||
|
{/if}
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<button type="submit">Signup</button>
|
||||||
|
|
||||||
|
<a class="back" href="/"> or Cancel </a>
|
||||||
|
</form>
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form action="POST">
|
<form method="POST" use:enhance>
|
||||||
{#if $errors._errors}
|
{#if $errors._errors}
|
||||||
<aside class="alert">
|
<aside class="alert">
|
||||||
<div class="alert-message">
|
<div class="alert-message">
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ export const actions = {
|
||||||
default: async ({ locals }) => {
|
default: async ({ locals }) => {
|
||||||
const session = await locals.auth.validate();
|
const session = await locals.auth.validate();
|
||||||
if (!session) {
|
if (!session) {
|
||||||
throw redirect(302, '/auth/sign-in');
|
throw redirect(302, '/auth/signin');
|
||||||
}
|
}
|
||||||
await auth.invalidateSession(session.sessionId); // invalidate session
|
await auth.invalidateSession(session.sessionId); // invalidate session
|
||||||
locals.auth.setSession(null); // remove cookie
|
locals.auth.setSession(null); // remove cookie
|
||||||
throw redirect(302, '/auth/sign-in');
|
throw redirect(302, '/auth/signin');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
password: true
|
password: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const { form, errors, enhance, delayed } = superForm(data.form, {
|
const { form, errors, constraints, enhance, delayed } = superForm(data.form, {
|
||||||
taintedMessage: null,
|
taintedMessage: null,
|
||||||
validators: signUpSchema,
|
validators: signUpSchema,
|
||||||
delayMs: 0,
|
delayMs: 0,
|
||||||
|
|
@ -80,7 +80,8 @@
|
||||||
name="username"
|
name="username"
|
||||||
type="username"
|
type="username"
|
||||||
placeholder="Username"
|
placeholder="Username"
|
||||||
autocomplete="uername"
|
autocomplete="email"
|
||||||
|
{...$constraints.username}
|
||||||
data-invalid={$errors.username}
|
data-invalid={$errors.username}
|
||||||
bind:value={$form.username}
|
bind:value={$form.username}
|
||||||
class="input"
|
class="input"
|
||||||
|
|
@ -97,6 +98,7 @@
|
||||||
name="password"
|
name="password"
|
||||||
type="password"
|
type="password"
|
||||||
placeholder="password"
|
placeholder="password"
|
||||||
|
{...$constraints.username}
|
||||||
data-invalid={$errors.password}
|
data-invalid={$errors.password}
|
||||||
bind:value={$form.password}
|
bind:value={$form.password}
|
||||||
class="input"
|
class="input"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue