-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path+page.svelte
More file actions
79 lines (73 loc) · 2.42 KB
/
Copy path+page.svelte
File metadata and controls
79 lines (73 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<script lang="ts">
import Loader2Icon from '@lucide/svelte/icons/loader-2';
import UserRoundPlusIcon from '@lucide/svelte/icons/user-round-plus';
import * as Form from '@repo/shared/components/ui/form';
import { Input } from '@repo/shared/components/ui/input';
import { toast } from 'svelte-sonner';
import { defaults, superForm } from 'sveltekit-superforms';
import { valibot } from 'sveltekit-superforms/adapters';
import { SignupSchema } from '$lib/schemas/auth';
import { userStore } from '$lib/stores';
const signupFormData = superForm(
defaults({ email: '', password: '', displayName: '' }, valibot(SignupSchema)),
{
SPA: true,
validators: valibot(SignupSchema),
onUpdate: async ({ form }) => {
if (!form.valid) return;
const data = form.data;
const { error } = await userStore.signUp(data.email, data.password, data.displayName);
if (error) {
toast.error(error.message);
}
},
},
);
const { form, enhance, submitting } = signupFormData;
</script>
<form use:enhance class="grid gap-6">
<Form.Field form={signupFormData} name="displayName">
<Form.Control>
{#snippet children({ props })}
<Form.Label>Display Name</Form.Label>
<Input {...props} type="text" placeholder="Your name" bind:value={$form.displayName} />
{/snippet}
</Form.Control>
<Form.FieldErrors />
</Form.Field>
<Form.Field form={signupFormData} name="email">
<Form.Control>
{#snippet children({ props })}
<Form.Label>Email</Form.Label>
<Input {...props} type="email" placeholder="your@email.com" bind:value={$form.email} />
{/snippet}
</Form.Control>
<Form.FieldErrors />
</Form.Field>
<Form.Field form={signupFormData} name="password">
<Form.Control>
{#snippet children({ props })}
<Form.Label>Password</Form.Label>
<Input
{...props}
type="password"
placeholder="••••••••"
autocomplete="new-password"
bind:value={$form.password}
/>
{/snippet}
</Form.Control>
<Form.FieldErrors />
</Form.Field>
<div class="flex justify-center">
<Form.Button disabled={$submitting}>
{#if $submitting}
<Loader2Icon class="animate-spin" />
Creating Account...
{:else}
<UserRoundPlusIcon />
Create Account
{/if}
</Form.Button>
</div>
</form>