-
-
Notifications
You must be signed in to change notification settings - Fork 507
fix(auth): preserve organization invitations through login #2528
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
Changes from all commits
f8e7a4e
b238305
c1fb450
d76b4b7
ba58f6a
09e9055
c15ee96
47f8579
b905fbd
79853bd
0879a6e
b3923fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| import { Spinner } from '$comp/ui/spinner'; | ||
| import { login } from '$features/auth/api.svelte'; | ||
| import { | ||
| accessToken, | ||
| enableAccountCreation, | ||
| enableOAuthLogin, | ||
| facebookClientId, | ||
|
|
@@ -26,26 +27,41 @@ | |
| googleClientId, | ||
| googleLogin, | ||
| liveLogin, | ||
| logout, | ||
| microsoftClientId | ||
| } from '$features/auth/index.svelte'; | ||
| import { type LoginFormData, LoginSchema } from '$features/auth/schemas'; | ||
| import { getSafeRedirectUrl } from '$features/shared/url'; | ||
| import { ariaInvalid, getFormErrorMessages, mapFieldErrors, problemDetailsToFormErrors } from '$shared/validation'; | ||
| import { createForm } from '@tanstack/svelte-form'; | ||
| import { onMount } from 'svelte'; | ||
|
|
||
| const defaultRedirect = resolve('/'); | ||
| const redirectUrl = getSafeRedirectUrl(page.url.searchParams.get('redirect'), defaultRedirect); | ||
| const inviteToken = page.url.searchParams.get('token'); | ||
| const canSignup = enableAccountCreation || !!inviteToken; | ||
| const signupUrl = inviteToken ? `${resolve('/(auth)/signup')}?token=${encodeURIComponent(inviteToken)}` : resolve('/(auth)/signup'); | ||
|
|
||
| onMount(async () => { | ||
| if (accessToken.current) { | ||
| try { | ||
| await logout(); | ||
|
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.
When a user opens this page with a stored access token and the logout request rejects because the API is unavailable, times out, or returns an unexpected error, this catch leaves Useful? React with 👍 / 👎. |
||
| } catch { | ||
| // The login flow can continue when an existing session cannot be ended. | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| const form = createForm(() => ({ | ||
| defaultValues: { | ||
| email: '', | ||
| invite_token: page.url.searchParams.get('token'), | ||
| invite_token: inviteToken, | ||
| password: '' | ||
| } as LoginFormData, | ||
| validators: { | ||
| onSubmit: LoginSchema, | ||
| onSubmitAsync: async ({ value }) => { | ||
| const response = await login(value.email, value.password); | ||
| const response = await login(value.email, value.password, value.invite_token); | ||
|
niemyjski marked this conversation as resolved.
niemyjski marked this conversation as resolved.
|
||
| if (response.ok) { | ||
| await goto(redirectUrl); | ||
| return null; | ||
|
|
@@ -62,7 +78,7 @@ | |
| } | ||
| </script> | ||
|
|
||
| <div class="mx-auto flex w-[calc(100vw-2rem)] max-w-lg flex-col items-center"> | ||
| <div class="mx-auto flex w-[calc(100vw-2rem)] max-w-lg flex-col items-center" inert={!!accessToken.current}> | ||
| <Card.Root class="w-full"> | ||
| <Card.Header> | ||
| <Logo /> | ||
|
|
@@ -137,16 +153,16 @@ | |
| </form.Field> | ||
| <form.Subscribe selector={(state) => state.isSubmitting}> | ||
| {#snippet children(isSubmitting)} | ||
| <div class={enableAccountCreation ? 'mt-4 grid grid-cols-2 gap-3' : 'mt-4'}> | ||
| <div class={canSignup ? 'mt-4 grid grid-cols-2 gap-3' : 'mt-4'}> | ||
| <Button type="submit" class="w-full" tabindex={3} disabled={isSubmitting}> | ||
| {#if isSubmitting} | ||
| <Spinner /> Logging in... | ||
| {:else} | ||
| Login | ||
| {/if} | ||
| </Button> | ||
| {#if enableAccountCreation} | ||
| <Button variant="secondary" href={resolve('/(auth)/signup')} class="w-full" tabindex={4}>Signup</Button> | ||
| {#if canSignup} | ||
| <Button variant="secondary" href={signupUrl} class="w-full" tabindex={4}>Signup</Button> | ||
| {/if} | ||
| </div> | ||
| {/snippet} | ||
|
|
@@ -161,38 +177,38 @@ | |
| </div> | ||
| <div class="grid grid-flow-col grid-cols-2 grid-rows-2 gap-4"> | ||
| {#if microsoftClientId} | ||
| <Button aria-label="Login with Microsoft" tabindex={4} onclick={() => liveLogin(redirectUrl)}> | ||
| <Button aria-label="Login with Microsoft" tabindex={4} onclick={() => liveLogin(redirectUrl, inviteToken)}> | ||
| <MicrosoftIcon class="size-4" /> Microsoft | ||
| </Button> | ||
| {/if} | ||
| {#if googleClientId} | ||
| <Button aria-label="Login with Google" tabindex={4} onclick={() => googleLogin(redirectUrl)}> | ||
| <Button aria-label="Login with Google" tabindex={4} onclick={() => googleLogin(redirectUrl, inviteToken)}> | ||
| <GoogleIcon class="size-4" /> Google | ||
| </Button> | ||
| {/if} | ||
| {#if facebookClientId} | ||
| <Button aria-label="Login with Facebook" tabindex={4} onclick={() => facebookLogin(redirectUrl)}> | ||
| <Button aria-label="Login with Facebook" tabindex={4} onclick={() => facebookLogin(redirectUrl, inviteToken)}> | ||
| <FacebookIcon class="size-4" /> Facebook | ||
| </Button> | ||
| {/if} | ||
| {#if gitHubClientId} | ||
| <Button aria-label="Login with GitHub" tabindex={4} onclick={() => githubLogin(redirectUrl)}> | ||
| <Button aria-label="Login with GitHub" tabindex={4} onclick={() => githubLogin(redirectUrl, inviteToken)}> | ||
| <GitHubIcon class="size-4" /> GitHub | ||
| </Button> | ||
| {/if} | ||
| </div> | ||
| {/if} | ||
|
|
||
| {#if enableAccountCreation} | ||
| {#if canSignup} | ||
| <P class="text-center text-sm"> | ||
| Not a member? | ||
| <A href={resolve('/(auth)/signup')} tabindex={5}>Start a free trial</A> | ||
| <A href={signupUrl} tabindex={5}>Start a free trial</A> | ||
| </P> | ||
| {/if} | ||
| </Card.Content> | ||
| </Card.Root> | ||
|
|
||
| {#if enableAccountCreation} | ||
| {#if canSignup} | ||
| <P class="text-muted-foreground mt-3! px-4 text-center text-sm"> | ||
| By signing up, you agree to our <A href="https://exceptionless.com/privacy" target="_blank">Privacy Policy</A> | ||
| and | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.