From 291e2337006e8f325066a0019b3bfd8ac07fb5eb Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Sat, 8 Nov 2025 05:02:17 +0100 Subject: [PATCH] chore: enable auto redirect on layout mount The use case for this is that if a person went from course page to invite page, and isn't authenticated then the user should be redirected to login page with a redirect query param --- apps/dashboard/src/hooks.server.ts | 4 ++-- .../CourseLandingPage/components/PaymentModal.svelte | 6 +++--- apps/dashboard/src/routes/+layout.svelte | 11 +++++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/apps/dashboard/src/hooks.server.ts b/apps/dashboard/src/hooks.server.ts index c83d017c..0af239ff 100644 --- a/apps/dashboard/src/hooks.server.ts +++ b/apps/dashboard/src/hooks.server.ts @@ -1,7 +1,7 @@ import type { Handle } from '@sveltejs/kit'; import { validateUser } from '$lib/utils/services/middlewares'; -const PUBLIC_ROUTES = [ +const PUBLIC_API_ROUTES = [ '/api/completion', 'student_prove_payment', 'teacher_student_buycourse', @@ -11,7 +11,7 @@ const PUBLIC_ROUTES = [ ]; function isPublicRoute(pathname: string) { - return PUBLIC_ROUTES.some((route) => pathname.includes(route)); + return PUBLIC_API_ROUTES.some((route) => pathname.includes(route)); } export const handle: Handle = async ({ event, resolve }) => { diff --git a/apps/dashboard/src/lib/components/CourseLandingPage/components/PaymentModal.svelte b/apps/dashboard/src/lib/components/CourseLandingPage/components/PaymentModal.svelte index 39914e8a..a0682b0d 100644 --- a/apps/dashboard/src/lib/components/CourseLandingPage/components/PaymentModal.svelte +++ b/apps/dashboard/src/lib/components/CourseLandingPage/components/PaymentModal.svelte @@ -20,7 +20,7 @@ email: '' }; - let errors = { + let errors: Record = { fullname: '', email: '' }; @@ -94,7 +94,7 @@ errorMessage={errors.email} /> -
+
-
+
Go to payment
{/if} diff --git a/apps/dashboard/src/routes/+layout.svelte b/apps/dashboard/src/routes/+layout.svelte index ea4bd3ef..7f0bebc2 100644 --- a/apps/dashboard/src/routes/+layout.svelte +++ b/apps/dashboard/src/routes/+layout.svelte @@ -29,6 +29,9 @@ import merge from 'lodash/merge'; import { onMount } from 'svelte'; import { MetaTags } from 'svelte-meta-tags'; + import isPublicRoute from '$lib/utils/functions/routes/isPublicRoute'; + import { isSupabaseTokenInLocalStorage } from '$lib/utils/functions/supabase'; + import { goto } from '$app/navigation'; import '../app.postcss'; @@ -65,10 +68,10 @@ handleResize(); - // if (!isSupabaseTokenInLocalStorage() && !isPublicRoute($page.url?.pathname)) { - // console.log('No auth token and is not a public route, redirect to login', path); - // return goto('/login?redirect=/' + path); - // } + if (!isSupabaseTokenInLocalStorage() && !isPublicRoute($page.url?.pathname)) { + console.log('No auth token and is not a public route, redirect to login', path); + return goto('/login?redirect=/' + path); + } const { data: authListener } = supabase.auth.onAuthStateChange((event, session) => { // Log key events