Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
7 changes: 7 additions & 0 deletions src/lib/auth/providers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const oauthProviders = [
{ id: 'hca', label: 'Hack Club', primary: true },
{ id: 'github', label: 'GitHub', primary: false },
{ id: 'google', label: 'Google', primary: false }
] as const;

export type OAuthProviderId = (typeof oauthProviders)[number]['id'];
50 changes: 28 additions & 22 deletions src/lib/components/login.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import * as Card from '$lib/components/ui/card/index.js';
import * as Item from '$lib/components/ui/item/index.js';
import Button from './ui/button/button.svelte';
import { authClient } from '$lib/auth-client';
import { authClient } from '$lib/auth/client';
import { useAuth } from '@mmailaender/convex-better-auth-svelte/svelte';
import { ArrowRight, ArrowRightIcon, LoaderCircle } from '@lucide/svelte';
import { toast } from 'svelte-sonner';
import Label from './ui/label/label.svelte';
import * as InputGroup from '$lib/components/ui/input-group/index.js';
import { oauthProviders } from '$lib/auth/providers';

const auth = useAuth();
let loading = $state(false);
Expand Down Expand Up @@ -52,27 +53,32 @@
<LoaderCircle class="size-5 animate-spin" />
</div>
{:else}
<Button
disabled={loading}
onclick={async () => {
loading = true;
try {
const { error } = await authClient.signIn.oauth2({
providerId: 'hca',
callbackURL: '/organizer'
});
if (error) {
loading = false;
toast.error('Something went wrong');
}
} catch {
loading = false;
toast.error('Something went wrong');
}
}}
>
Continue with Hack Club
</Button>
<div class="grid gap-4">
{#each oauthProviders as provider (provider.id)}
<Button
variant={provider.primary ? 'default' : 'outline'}
disabled={loading}
onclick={async () => {
loading = true;
try {
const { error } = await authClient.signIn.oauth2({
providerId: provider.id,
callbackURL: '/organizer'
});
if (error) {
loading = false;
toast.error('Something went wrong');
}
} catch {
loading = false;
toast.error('Something went wrong');
}
}}
>
Continue with {provider.label}
</Button>
{/each}
</div>
<form class="flex w-full flex-col gap-2">
<Label for="email-{id}">Email</Label>
<InputGroup.Root class="w-full">
Expand Down
17 changes: 6 additions & 11 deletions src/lib/components/organizer/sidebar/account-dialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Label from '$lib/components/ui/label/label.svelte';

import { useSidebar } from '$lib/components/ui/sidebar';
import { authClient } from '$lib/auth-client';
import { authClient } from '$lib/auth/client';
import { goto } from '$app/navigation';
import { toast } from 'svelte-sonner';
import {
Expand All @@ -24,6 +24,7 @@
} from '@lucide/svelte';
import { UAParser } from 'ua-parser-js';
import { cn } from '$lib/utils';
import { oauthProviders } from '$lib/auth/providers';

let {
open = $bindable(),
Expand Down Expand Up @@ -87,12 +88,6 @@
accountId: string;
};

const providerConfigs = [
{ id: 'hca', label: 'Hack Club' },
{ id: 'github', label: 'GitHub' },
{ id: 'google', label: 'Google' }
] as const;

function parseSession(session: SessionItem): ParsedSession {
const ua = new UAParser(session.userAgent ?? '');
const browser = ua.getBrowser();
Expand Down Expand Up @@ -174,7 +169,7 @@
if (error) throw error;
} catch (err) {
toast.error(
`Failed to link ${providerConfigs.find((p) => p.id === providerId)?.label ?? providerId}`
`Failed to link ${oauthProviders.find((p) => p.id === providerId)?.label ?? providerId}`
);
console.error(err);
linkingProvider = { ...linkingProvider, [providerId]: false };
Expand All @@ -194,11 +189,11 @@
if (error) throw error;
accounts = accounts.filter((account) => account.id !== linked.id);
toast.success(
`${providerConfigs.find((p) => p.id === providerId)?.label ?? providerId} unlinked`
`${oauthProviders.find((p) => p.id === providerId)?.label ?? providerId} unlinked`
);
} catch (err) {
toast.error(
`Failed to unlink ${providerConfigs.find((p) => p.id === providerId)?.label ?? providerId}`
`Failed to unlink ${oauthProviders.find((p) => p.id === providerId)?.label ?? providerId}`
);
console.error(err);
} finally {
Expand Down Expand Up @@ -401,7 +396,7 @@
<p class="text-xs text-muted-foreground">Link or unlink sign-in providers.</p>
</div>
<div class="space-y-2 p-4">
{#each providerConfigs as provider (provider.id)}
{#each oauthProviders as provider (provider.id)}
{@const linked = getLinkedAccount(provider.id)}
<div class="flex items-center justify-between rounded-sm border px-3 py-2.5">
<div class="text-sm font-medium">{provider.label}</div>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/organizer/sidebar/user.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { ChevronUpIcon, LogOutIcon, SettingsIcon } from '@lucide/svelte';
import type { FunctionReturnType } from 'convex/server';
import { api } from '$convex/_generated/api';
import { authClient } from '$lib/auth-client';
import { authClient } from '$lib/auth/client';
import { toast } from 'svelte-sonner';
import { goto } from '$app/navigation';
import { useQuery } from '@mmailaender/convex-svelte';
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/ui/sidebar/sidebar-trigger.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</script>

<Button
bind:ref
data-sidebar="trigger"
data-slot="sidebar-trigger"
variant="ghost"
Expand Down
2 changes: 1 addition & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import favicon from '$lib/assets/favicon.svg';
import { createSvelteAuthClient } from '@mmailaender/convex-better-auth-svelte/svelte';

import { authClient } from '$lib/auth-client';
import { authClient } from '$lib/auth/client';
import { ModeWatcher } from 'mode-watcher';
import { Toaster } from '$lib/components/ui/sonner/index.js';
import * as Tooltip from '$lib/components/ui/tooltip/index.js';
Expand Down
Loading