|
5 | 5 | import Button from './ui/button/button.svelte'; |
6 | 6 | import { authClient } from '$lib/auth-client'; |
7 | 7 | import { useAuth } from '@mmailaender/convex-better-auth-svelte/svelte'; |
8 | | - import { ArrowRight, ArrowRightIcon } from '@lucide/svelte'; |
| 8 | + import { ArrowRight, ArrowRightIcon, LoaderCircle } from '@lucide/svelte'; |
9 | 9 | import { toast } from 'svelte-sonner'; |
10 | 10 | import Label from './ui/label/label.svelte'; |
11 | 11 | import * as InputGroup from '$lib/components/ui/input-group/index.js'; |
|
47 | 47 | <Card.Title>Log in as an organizer</Card.Title> |
48 | 48 | </Card.Header> |
49 | 49 | <Card.Content class="space-y-8"> |
50 | | - <Button |
51 | | - disabled={loading} |
52 | | - onclick={async () => { |
53 | | - loading = true; |
54 | | - toast.promise( |
55 | | - authClient.signIn |
56 | | - .oauth2({ |
| 50 | + {#if loading} |
| 51 | + <div class="flex min-h-32 flex-col items-center justify-center gap-3"> |
| 52 | + <LoaderCircle class="size-5 animate-spin" /> |
| 53 | + </div> |
| 54 | + {:else} |
| 55 | + <Button |
| 56 | + disabled={loading} |
| 57 | + onclick={async () => { |
| 58 | + loading = true; |
| 59 | + try { |
| 60 | + const { error } = await authClient.signIn.oauth2({ |
57 | 61 | providerId: 'hca', |
58 | 62 | callbackURL: '/organizer' |
59 | | - }) |
60 | | - .then(({ data, error }) => { |
61 | | - if (error) { |
62 | | - loading = false; |
63 | | - throw error; |
64 | | - } |
65 | | - return data; |
66 | | - }), |
67 | | - { |
68 | | - loading: 'Loading...', |
69 | | - success: 'Redirecting...', |
70 | | - error: 'Something went wrong' |
| 63 | + }); |
| 64 | + if (error) { |
| 65 | + loading = false; |
| 66 | + toast.error('Something went wrong'); |
| 67 | + } |
| 68 | + } catch { |
| 69 | + loading = false; |
| 70 | + toast.error('Something went wrong'); |
71 | 71 | } |
72 | | - ); |
73 | | - }}>Continue with Hack Club</Button |
74 | | - > |
75 | | - <form class="flex w-full flex-col gap-2"> |
76 | | - <Label for="email-{id}">Email</Label> |
77 | | - <InputGroup.Root class="w-full"> |
78 | | - <InputGroup.Input |
79 | | - type="email" |
80 | | - name="email" |
81 | | - id="email-{id}" |
82 | | - required |
83 | | - placeholder="iwill@hackthisclub.com" |
84 | | - /> |
85 | | - <InputGroup.Addon align="inline-end"> |
86 | | - <InputGroup.Button variant="default" type="submit"> |
87 | | - <ArrowRightIcon /> |
88 | | - Send Code |
89 | | - </InputGroup.Button> |
90 | | - </InputGroup.Addon> |
91 | | - </InputGroup.Root> |
92 | | - </form> |
| 72 | + }} |
| 73 | + > |
| 74 | + Continue with Hack Club |
| 75 | + </Button> |
| 76 | + <form class="flex w-full flex-col gap-2"> |
| 77 | + <Label for="email-{id}">Email</Label> |
| 78 | + <InputGroup.Root class="w-full"> |
| 79 | + <InputGroup.Input |
| 80 | + type="email" |
| 81 | + name="email" |
| 82 | + id="email-{id}" |
| 83 | + required |
| 84 | + placeholder="iwill@hackthisclub.com" |
| 85 | + /> |
| 86 | + <InputGroup.Addon align="inline-end"> |
| 87 | + <InputGroup.Button variant="default" type="submit"> |
| 88 | + <ArrowRightIcon /> |
| 89 | + Send Code |
| 90 | + </InputGroup.Button> |
| 91 | + </InputGroup.Addon> |
| 92 | + </InputGroup.Root> |
| 93 | + </form> |
| 94 | + {/if} |
93 | 95 | </Card.Content> |
94 | 96 | {/if} |
95 | 97 | </Card.Root> |
|
0 commit comments