|
2 | 2 | import {
|
3 | 3 | Styles
|
4 | 4 | } from 'sveltestrap';
|
5 |
| - import { onMount } from 'svelte'; |
| 5 | + import { onMount, getContext } from 'svelte'; |
6 | 6 | import { goto } from '$app/navigation';
|
7 |
| - import { page } from '$app/stores'; |
| 7 | + import { page, type Writable } from '$app/stores'; |
8 | 8 | import AuthService from '$lib/utils/AuthService';
|
9 | 9 | import type { User } from 'oidc-client-ts';
|
| 10 | + import type { SHLAdminParams, SHLClient } from '$lib/utils/managementClient'; |
| 11 | +
|
| 12 | + let shlStore: Writable<SHLAdminParams[]> = getContext('shlStore'); |
| 13 | + let shlClient: SHLClient = getContext('shlClient'); |
10 | 14 |
|
11 | 15 | let authService = AuthService.Instance;
|
12 | 16 | onMount(async () => {
|
13 | 17 | let newUser: User | undefined;
|
14 | 18 | try {
|
15 | 19 | newUser = await authService.signinCallback();
|
16 | 20 | if (newUser) {
|
17 |
| - let redirectUrl = authService.getRedirectUrl(); |
18 |
| - // avoid redirecting to the same page |
19 |
| - if (redirectUrl && !redirectUrl.includes($page.url.pathname)) { |
20 |
| - goto(redirectUrl); |
21 |
| - } else { |
22 |
| - goto('/home'); |
23 |
| - } |
| 21 | + setTimeout(async () => { |
| 22 | + window.dispatchEvent(new CustomEvent('userFound', { |
| 23 | + detail: { message: 'Hello from another component!' } |
| 24 | + })); |
| 25 | + $shlStore = await shlClient.getUserShls(); |
| 26 | + let redirectUrl = authService.getRedirectUrl(); |
| 27 | + // avoid redirecting to the same page |
| 28 | + if (redirectUrl && !redirectUrl.includes($page.url.pathname)) { |
| 29 | + goto(redirectUrl); |
| 30 | + } else { |
| 31 | + goto('/home'); |
| 32 | + } |
| 33 | + }, 100); |
24 | 34 | }
|
25 | 35 | } catch (error) {
|
26 | 36 | console.error("No authentication parameters found.");
|
|
0 commit comments