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:
@@ -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 }) => {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
email: ''
|
||||
};
|
||||
|
||||
let errors = {
|
||||
let errors: Record<string, string> = {
|
||||
fullname: '',
|
||||
email: ''
|
||||
};
|
||||
@@ -94,7 +94,7 @@
|
||||
errorMessage={errors.email}
|
||||
/>
|
||||
|
||||
<div class="mt-5 flex items-center flex-row-reverse">
|
||||
<div class="mt-5 flex flex-row-reverse items-center">
|
||||
<PrimaryButton
|
||||
className="px-6 py-3"
|
||||
label={paymentLink ? 'Next' : 'Finish'}
|
||||
@@ -107,7 +107,7 @@
|
||||
You will now be taken to a payment page, once you've paid send a proof of payment to the
|
||||
course admin
|
||||
</p>
|
||||
<div class="mt-5 flex items-center flex-row-reverse">
|
||||
<div class="mt-5 flex flex-row-reverse items-center">
|
||||
<Link href={paymentLink} target="_blank" on:click={onClickPaymentLink}>Go to payment</Link>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user