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
This commit is contained in:
Rotimi Best
2025-11-08 05:02:17 +01:00
parent 570b809111
commit 291e233700
3 changed files with 12 additions and 9 deletions
+7 -4
View File
@@ -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