From 8cf548c4dc95b09486455cb62b2a01a694447eeb Mon Sep 17 00:00:00 2001 From: Aristide Urli Date: Mon, 14 Oct 2024 09:26:48 +0200 Subject: [PATCH] feat(client): Redirect to /client/commande from /auth when already authenticated --- frontend/src/routes/auth/+page.svelte | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/frontend/src/routes/auth/+page.svelte b/frontend/src/routes/auth/+page.svelte index 15d1442..8ce2b96 100644 --- a/frontend/src/routes/auth/+page.svelte +++ b/frontend/src/routes/auth/+page.svelte @@ -2,8 +2,26 @@ import { api } from "$lib/config/config"; import { page } from '$app/stores'; import Error from "$lib/components/error.svelte"; + import { onMount } from "svelte"; + import { accountsApi } from '$lib/requests/requests'; + import { goto } from "$app/navigation"; const noAccountError = $page.url.searchParams.has("noaccount") + + // Skip auth if the user is already connected + onMount(() => { + accountsApi() + .getAccount({ + withCredentials: true + }) + .then(r => { + goto("/client/commande") + }) + .catch(e => { + return () => {}; + }) + }); +