Skip to content

Commit 002b849

Browse files
committed
Add support for global context fetched server side. Usefull for fetching auth config on start.
1 parent 91aee88 commit 002b849

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script lang="ts">
2+
import logo from "$lib/assets/img/logo-white.svg";
3+
</script>
4+
5+
<img alt="AgentLabs Logo" src={logo} />

frontend/src/routes/+layout.server.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { ServerLoad } from "@sveltejs/kit";
2+
import type { MainLayoutContext } from "./types";
3+
4+
const waitForDelayMs = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
5+
6+
export const load: ServerLoad = async (): Promise<MainLayoutContext> => {
7+
return {
8+
lazy: {
9+
context: new Promise((resolve) => {
10+
return waitForDelayMs(1000).then(() => {
11+
resolve({
12+
tenantName: "AgentLabs Team",
13+
allowedSignInMethods: ["passwordless-email", "google", "github", "gitlab"]
14+
});
15+
});
16+
})
17+
}
18+
};
19+
};

frontend/src/routes/+layout.svelte

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
<script>
2-
import '../app.css';
1+
<script lang="ts">
2+
import type { LayoutData } from "./$types";
3+
import "../app.css";
4+
import AgentLabsLogo from "$lib/components/common/logo/AgentLabsLogo.svelte";
5+
6+
export let data: LayoutData;
37
</script>
48

5-
<slot></slot>
9+
{#await data.lazy.context}
10+
<div class="min-h-screen bg-background-primary flex items-center justify-center">
11+
<div class="flex flex-col animate-pulse">
12+
<AgentLabsLogo />
13+
</div>
14+
</div>
15+
{:then context}
16+
<slot />
17+
{/await}

frontend/src/routes/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const SignInMethods = ["passwordless-email", "google", "github", "gitlab"] as const;
2+
export type SignInMethod = (typeof SignInMethods)[number];
3+
4+
export type MainLayoutContext = {
5+
lazy: {
6+
context: Promise<{
7+
tenantName: string;
8+
allowedSignInMethods: SignInMethod[];
9+
}>;
10+
};
11+
};

0 commit comments

Comments
 (0)