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 type { Handle } from '@sveltejs/kit';
|
||||||
import { validateUser } from '$lib/utils/services/middlewares';
|
import { validateUser } from '$lib/utils/services/middlewares';
|
||||||
|
|
||||||
const PUBLIC_ROUTES = [
|
const PUBLIC_API_ROUTES = [
|
||||||
'/api/completion',
|
'/api/completion',
|
||||||
'student_prove_payment',
|
'student_prove_payment',
|
||||||
'teacher_student_buycourse',
|
'teacher_student_buycourse',
|
||||||
@@ -11,7 +11,7 @@ const PUBLIC_ROUTES = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
function isPublicRoute(pathname: string) {
|
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 }) => {
|
export const handle: Handle = async ({ event, resolve }) => {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
email: ''
|
email: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
let errors = {
|
let errors: Record<string, string> = {
|
||||||
fullname: '',
|
fullname: '',
|
||||||
email: ''
|
email: ''
|
||||||
};
|
};
|
||||||
@@ -94,7 +94,7 @@
|
|||||||
errorMessage={errors.email}
|
errorMessage={errors.email}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="mt-5 flex items-center flex-row-reverse">
|
<div class="mt-5 flex flex-row-reverse items-center">
|
||||||
<PrimaryButton
|
<PrimaryButton
|
||||||
className="px-6 py-3"
|
className="px-6 py-3"
|
||||||
label={paymentLink ? 'Next' : 'Finish'}
|
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
|
You will now be taken to a payment page, once you've paid send a proof of payment to the
|
||||||
course admin
|
course admin
|
||||||
</p>
|
</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>
|
<Link href={paymentLink} target="_blank" on:click={onClickPaymentLink}>Go to payment</Link>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -29,6 +29,9 @@
|
|||||||
import merge from 'lodash/merge';
|
import merge from 'lodash/merge';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { MetaTags } from 'svelte-meta-tags';
|
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';
|
import '../app.postcss';
|
||||||
|
|
||||||
@@ -65,10 +68,10 @@
|
|||||||
|
|
||||||
handleResize();
|
handleResize();
|
||||||
|
|
||||||
// if (!isSupabaseTokenInLocalStorage() && !isPublicRoute($page.url?.pathname)) {
|
if (!isSupabaseTokenInLocalStorage() && !isPublicRoute($page.url?.pathname)) {
|
||||||
// console.log('No auth token and is not a public route, redirect to login', path);
|
console.log('No auth token and is not a public route, redirect to login', path);
|
||||||
// return goto('/login?redirect=/' + path);
|
return goto('/login?redirect=/' + path);
|
||||||
// }
|
}
|
||||||
|
|
||||||
const { data: authListener } = supabase.auth.onAuthStateChange((event, session) => {
|
const { data: authListener } = supabase.auth.onAuthStateChange((event, session) => {
|
||||||
// Log key events
|
// Log key events
|
||||||
|
|||||||
Reference in New Issue
Block a user