|
1 | 1 | <script lang="ts"> |
| 2 | + import { afterNavigate, goto, replaceState } from '$app/navigation'; |
2 | 3 | import { resolve } from '$app/paths'; |
3 | 4 | import { page } from '$app/state'; |
4 | 5 | import * as Card from '$lib/components/ui/card/index.js'; |
5 | 6 | import { FieldDescription } from '$lib/components/ui/field/index.js'; |
6 | 7 | import { registerBreadcrumbs } from '$lib/state/breadcrumbs-state.svelte'; |
| 8 | + import { getOAuthErrorMessage } from '$lib/auth/oauth-errors'; |
| 9 | + import { tick } from 'svelte'; |
7 | 10 |
|
8 | 11 | registerBreadcrumbs(() => [{ label: 'Authentication Error' }]); |
9 | 12 |
|
10 | | - let error = $derived(page.url.searchParams.get('error')); |
| 13 | + let errorCode = $state<string>(); |
| 14 | +
|
| 15 | + afterNavigate(async () => { |
| 16 | + const err = page.url.searchParams.get('error'); |
| 17 | + if (err === 'emailAlreadyRegistered') { |
| 18 | + await goto(resolve(`/login?error=${encodeURIComponent(err)}`), { replaceState: true }); |
| 19 | + return; |
| 20 | + } |
| 21 | + errorCode = err ?? 'unknown'; |
| 22 | + await tick(); |
| 23 | + replaceState(resolve('/oauth/error'), {}); |
| 24 | + }); |
11 | 25 | </script> |
12 | 26 |
|
13 | | -<Card.Root> |
14 | | - <Card.Header class="text-center"> |
15 | | - <Card.Title class="text-xl">Authentication Error</Card.Title> |
16 | | - <Card.Description>Something went wrong during authentication</Card.Description> |
17 | | - </Card.Header> |
18 | | - <Card.Content> |
19 | | - <p class="text-destructive text-center" role="alert">{error}</p> |
20 | | - <FieldDescription class="mt-4 text-center"> |
21 | | - <a href={resolve('/login')}>Back to login</a> |
22 | | - </FieldDescription> |
23 | | - </Card.Content> |
24 | | -</Card.Root> |
| 27 | +{#if errorCode} |
| 28 | + <Card.Root> |
| 29 | + <Card.Header class="text-center"> |
| 30 | + <Card.Title class="text-xl">Authentication Error</Card.Title> |
| 31 | + </Card.Header> |
| 32 | + <Card.Content> |
| 33 | + <p class="text-destructive text-center" role="alert">{getOAuthErrorMessage(errorCode)}</p> |
| 34 | + <FieldDescription class="mt-4 text-center"> |
| 35 | + <a href={resolve('/login')}>Back to login</a> |
| 36 | + </FieldDescription> |
| 37 | + </Card.Content> |
| 38 | + </Card.Root> |
| 39 | +{/if} |
0 commit comments