diff --git a/frontend/src/lib/kratos/index.ts b/frontend/src/lib/kratos/index.ts index bf96e08..6f0fdca 100644 --- a/frontend/src/lib/kratos/index.ts +++ b/frontend/src/lib/kratos/index.ts @@ -36,10 +36,10 @@ export async function getIdentity(): Promise { // ----------------------------------------------------------------------------- export async function getDataModels( flow: string, - flowId: string, + flowId: string ): Promise { if (!flowId) throw new Error("no flowId"); - if (!browser) throw new Error("no browser environment"); + // if (!browser) throw new Error("no browser environment"); const url = `${KRATOS}/self-service/${flow}/flows?id=${flowId}`; const res = await get(url); diff --git a/frontend/src/routes/auth/login/+page.svelte b/frontend/src/routes/auth/login/+page.svelte index c7c19ac..9bafc82 100644 --- a/frontend/src/routes/auth/login/+page.svelte +++ b/frontend/src/routes/auth/login/+page.svelte @@ -6,16 +6,19 @@ import Form from "$lib/components/kratos/form.svelte"; import Messages from "$lib/components/kratos/messages.svelte"; - const flowId = getFlowId($page.url.search); - if (browser && !flowId) - window.location.href = `${KRATOS}/self-service/login/browser`; + // const flowId = getFlowId($page.url.search); --> + // if (browser && !flowId) --> + // window.location.href = `${KRATOS}/self-service/login/browser`; --> - const pr = getDataModels("login", flowId); + // const pr = getDataModels("login", flowId); --> + + export let data: PageData; + $: pr = data.pr;
- {#await pr then dm} {#if dm.instanceOf === "KratosForm"} + {#await data.pr then dm} {#if dm.instanceOf === "KratosForm"}

Sign in

diff --git a/frontend/src/routes/auth/login/+page.ts b/frontend/src/routes/auth/login/+page.ts new file mode 100644 index 0000000..b68724d --- /dev/null +++ b/frontend/src/routes/auth/login/+page.ts @@ -0,0 +1,16 @@ +import { getFlowId, getDataModels } from "$lib/kratos"; +import { page } from "$app/stores"; +import { browser } from "$app/environment"; +import { KRATOS } from "$lib/config"; + +/** @type {import('./$types').PageLoad} */ +export async function load({ url }) { + const flowId = getFlowId(url.search); + + if (browser && !flowId) + window.location.href = `${KRATOS}/self-service/login/browser`; + + const pr = getDataModels("login", flowId); + + return { pr: pr }; +} diff --git a/frontend/src/routes/dashboard/+page.server.ts b/frontend/src/routes/dashboard/+page.server.ts index 238d7ea..2074ef1 100644 --- a/frontend/src/routes/dashboard/+page.server.ts +++ b/frontend/src/routes/dashboard/+page.server.ts @@ -1,3 +1,6 @@ +import { get } from "svelte/store"; +import identity from "$lib/stores/kratos/identity"; + type Question = { text: string; }; @@ -14,11 +17,13 @@ type Quiz = { /** @type {import('./$types').PageLoad} */ export async function load() { - const res = await fetch("http://localhost:8080/quizzes"); - const response = await res.json(); + const _identity = get(identity); + if (_identity) { + const res = await fetch("http://localhost:8080/quizzes"); + const response = await res.json(); - console.log(response); - if (response.status === "success") { - return { quizzes: (await response.content) as Quiz[] }; + if (response.status === "success") { + return { quizzes: (await response.content) as Quiz[] }; + } } } diff --git a/frontend/src/routes/dashboard/+page.svelte b/frontend/src/routes/dashboard/+page.svelte index 51ea996..76f1807 100644 --- a/frontend/src/routes/dashboard/+page.svelte +++ b/frontend/src/routes/dashboard/+page.svelte @@ -1,21 +1,21 @@