-
Notifications
You must be signed in to change notification settings - Fork 0
workos-auth/core: Replace Clerk with WorkOS AuthKit #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,30 @@ | ||
| <script lang="ts"> | ||
| import SignedIn from 'clerk-sveltekit/client/SignedIn.svelte'; | ||
| import SignedOut from 'clerk-sveltekit/client/SignedOut.svelte'; | ||
| import UserButton from 'clerk-sveltekit/client/UserButton.svelte'; | ||
| import ClerkLoaded from 'clerk-sveltekit/client/ClerkLoaded.svelte'; | ||
| import ClerkLoading from 'clerk-sveltekit/client/ClerkLoading.svelte'; | ||
| import DotMatrixLoader from '$lib/components/dotmatrix-loader.svelte'; | ||
| import { resolve } from '$app/paths'; | ||
|
|
||
| let { userId = null }: { userId?: string | null } = $props(); | ||
|
|
||
| const loadingLabel = $derived(userId ? 'Loading account' : 'Loading sign in status'); | ||
| let { userId = null, email = null }: { userId?: string | null; email?: string | null } = $props(); | ||
| </script> | ||
|
|
||
| <div class="flex shrink-0 items-center"> | ||
| <ClerkLoading> | ||
| <div | ||
| class="flex items-center justify-center {userId ? 'size-8' : 'h-8 w-16'}" | ||
| aria-hidden="true" | ||
| > | ||
| <DotMatrixLoader variant="inline" ariaLabel={loadingLabel} /> | ||
| {#if userId} | ||
| <div class="flex min-w-0 flex-col items-end gap-1.5"> | ||
| {#if email} | ||
| <span class="max-w-full truncate font-mono text-[10px] text-muted-foreground">{email}</span> | ||
| {/if} | ||
| <form method="POST" action={resolve('/sign-out')}> | ||
| <button | ||
| type="submit" | ||
| class="rounded-md border border-border bg-card px-3 py-1.5 font-mono text-xs text-foreground transition-colors hover:bg-secondary" | ||
| > | ||
| Sign out | ||
| </button> | ||
| </form> | ||
| </div> | ||
| <span class="sr-only">{loadingLabel}</span> | ||
| </ClerkLoading> | ||
| <ClerkLoaded> | ||
| <SignedIn> | ||
| <UserButton | ||
| afterSignOutUrl="/sign-in" | ||
| appearance={{ | ||
| elements: { | ||
| rootBox: 'flex items-center', | ||
| avatarBox: 'h-8 w-8 rounded-md ring-1 ring-border' | ||
| } | ||
| }} | ||
| /> | ||
| </SignedIn> | ||
| <SignedOut> | ||
| <a | ||
| class="rounded-md border border-border bg-card px-3 py-1.5 font-mono text-xs text-foreground transition-colors hover:bg-secondary" | ||
| href={resolve('/sign-in')} | ||
| > | ||
| Sign in | ||
| </a> | ||
| </SignedOut> | ||
| </ClerkLoaded> | ||
| {:else} | ||
| <a | ||
| class="rounded-md border border-border bg-card px-3 py-1.5 font-mono text-xs text-foreground transition-colors hover:bg-secondary" | ||
| href={resolve('/sign-in')} | ||
| > | ||
| Sign in | ||
| </a> | ||
| {/if} | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| import { redirect } from '@sveltejs/kit'; | ||
| import { authKit } from '@workos/authkit-sveltekit'; | ||
| import { readPostAuthRedirectUrl, readUserId } from '$lib/server/auth'; | ||
|
|
||
| export function load(event) { | ||
| export async function load(event) { | ||
| if (readUserId(event)) { | ||
| throw redirect(303, readPostAuthRedirectUrl(event)); | ||
| } | ||
| return {}; | ||
| return { | ||
| signInUrl: await authKit.getSignInUrl({ returnTo: readPostAuthRedirectUrl(event) }) | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,19 +1,12 @@ | ||||||||||||
| <script lang="ts"> | ||||||||||||
| import { page } from '$app/state'; | ||||||||||||
| import { onMount } from 'svelte'; | ||||||||||||
| import AuthWidgetLoading from '$lib/components/auth-widget-loading.svelte'; | ||||||||||||
| import PostAuthRedirect from '$lib/components/post-auth-redirect.svelte'; | ||||||||||||
| import ClerkLoaded from 'clerk-sveltekit/client/ClerkLoaded.svelte'; | ||||||||||||
| import ClerkLoading from 'clerk-sveltekit/client/ClerkLoading.svelte'; | ||||||||||||
| import SignIn from 'clerk-sveltekit/client/SignIn.svelte'; | ||||||||||||
| import { safeRedirectPath } from '$lib/auth-redirect'; | ||||||||||||
|
|
||||||||||||
| const redirectUrl = $derived( | ||||||||||||
| safeRedirectPath( | ||||||||||||
| page.url.searchParams.get('redirect_url') ?? | ||||||||||||
| page.url.searchParams.get('redirectUrl') ?? | ||||||||||||
| page.url.searchParams.get('redirectAfterAuth') | ||||||||||||
| ) | ||||||||||||
| ); | ||||||||||||
| let { data }: { data: { signInUrl: string } } = $props(); | ||||||||||||
|
|
||||||||||||
| onMount(() => { | ||||||||||||
| window.location.href = data.signInUrl; | ||||||||||||
| }); | ||||||||||||
| </script> | ||||||||||||
|
|
||||||||||||
| <svelte:head><title>Sign in | FlightLog</title></svelte:head> | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
|
@@ -26,16 +19,6 @@ | |||||||||||
| </p> | ||||||||||||
| <h1 class="mt-2 text-2xl font-semibold text-foreground">Sign in to FlightLog</h1> | ||||||||||||
| </div> | ||||||||||||
| <ClerkLoading> | ||||||||||||
| <AuthWidgetLoading /> | ||||||||||||
| </ClerkLoading> | ||||||||||||
| <ClerkLoaded let:clerk> | ||||||||||||
| {#if clerk?.user} | ||||||||||||
| <PostAuthRedirect to={redirectUrl} /> | ||||||||||||
| <AuthWidgetLoading /> | ||||||||||||
| {:else} | ||||||||||||
| <SignIn {redirectUrl} signUpUrl="/sign-up" /> | ||||||||||||
| {/if} | ||||||||||||
| </ClerkLoaded> | ||||||||||||
| <AuthWidgetLoading /> | ||||||||||||
| </section> | ||||||||||||
| </main> | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| import { redirect } from '@sveltejs/kit'; | ||
| import { readPostAuthRedirectUrl, readUserId } from '$lib/server/auth'; | ||
| import { authKit } from '@workos/authkit-sveltekit'; | ||
| import { readUserId } from '$lib/server/auth'; | ||
|
|
||
| export function load(event) { | ||
| export async function load(event) { | ||
| if (readUserId(event)) { | ||
| throw redirect(303, readPostAuthRedirectUrl(event)); | ||
| throw redirect(303, '/runs'); | ||
| } | ||
| return {}; | ||
| return { | ||
| signUpUrl: await authKit.getSignUpUrl({ returnTo: '/runs' }) | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,12 @@ | ||||||||||||
| <script lang="ts"> | ||||||||||||
| import { onMount } from 'svelte'; | ||||||||||||
| import AuthWidgetLoading from '$lib/components/auth-widget-loading.svelte'; | ||||||||||||
| import ClerkLoaded from 'clerk-sveltekit/client/ClerkLoaded.svelte'; | ||||||||||||
| import ClerkLoading from 'clerk-sveltekit/client/ClerkLoading.svelte'; | ||||||||||||
| import SignUp from 'clerk-sveltekit/client/SignUp.svelte'; | ||||||||||||
|
|
||||||||||||
| let { data }: { data: { signUpUrl: string } } = $props(); | ||||||||||||
|
|
||||||||||||
| onMount(() => { | ||||||||||||
| window.location.href = data.signUpUrl; | ||||||||||||
| }); | ||||||||||||
| </script> | ||||||||||||
|
|
||||||||||||
| <svelte:head><title>Sign up | FlightLog</title></svelte:head> | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
|
@@ -15,11 +19,6 @@ | |||||||||||
| </p> | ||||||||||||
| <h1 class="mt-2 text-2xl font-semibold text-foreground">Create your FlightLog account</h1> | ||||||||||||
| </div> | ||||||||||||
| <ClerkLoading> | ||||||||||||
| <AuthWidgetLoading /> | ||||||||||||
| </ClerkLoading> | ||||||||||||
| <ClerkLoaded> | ||||||||||||
| <SignUp redirectUrl="/runs" signInUrl="/sign-in" /> | ||||||||||||
| </ClerkLoaded> | ||||||||||||
| <AuthWidgetLoading /> | ||||||||||||
| </section> | ||||||||||||
| </main> | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { authKit } from '@workos/authkit-sveltekit'; | ||
| import type { RequestHandler } from './$types'; | ||
|
|
||
| export const GET: RequestHandler = async (event) => { | ||
| const handler = authKit.handleCallback(); | ||
| return handler(event); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { authKit } from '@workos/authkit-sveltekit'; | ||
| import type { RequestHandler } from './$types'; | ||
|
|
||
| export const POST: RequestHandler = async (event) => { | ||
| return authKit.signOut(event); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configureAuthKitparameters fall back to an empty string when the corresponding env var is absent. A missingcookiePasswordin particular will causeiron-webcryptoto throw a crypto error at request time (it requires a password of at least 32 characters), making the failure happen silently on the first authenticated request rather than at startup. Asserting these values are present at boot makes misconfiguration immediately visible.