Redirect to login without token and not on a public route
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
isQuizPage,
|
||||
} from '../utils/functions/app';
|
||||
import showAppsSideBar from '../utils/functions/showAppsSideBar';
|
||||
import isPublicRoute from '../utils/functions/routes/isPublicRoute';
|
||||
import { user, profile } from '../utils/store/user';
|
||||
import { getSupabase } from '../utils/functions/supabase';
|
||||
import { isMobile } from '../utils/store/useMobile';
|
||||
@@ -194,6 +195,17 @@
|
||||
|
||||
handleResize();
|
||||
|
||||
if (
|
||||
!localStorage.getItem('supabase.auth.token') &&
|
||||
!isPublicRoute($page.path)
|
||||
) {
|
||||
console.log(
|
||||
'No auth token and is not a public route, redirect to login',
|
||||
path
|
||||
);
|
||||
return goto('/login');
|
||||
}
|
||||
|
||||
const { data: authListener } = supabase.auth.onAuthStateChange(
|
||||
(event, session) => {
|
||||
// Log key events
|
||||
|
||||
@@ -3,6 +3,7 @@ export const ROUTE = {
|
||||
DASHBOARD: '/dashboard',
|
||||
ONBOARDING: '/onboarding',
|
||||
COURSES: '/courses',
|
||||
COURSE: '/course',
|
||||
LOGIN: '/login',
|
||||
SIGN_UP: '/signup',
|
||||
PROFILE: '/profile',
|
||||
@@ -14,11 +15,12 @@ export const ROUTE = {
|
||||
};
|
||||
|
||||
export const PUBLIC_ROUTES = [
|
||||
ROUTE.HOME,
|
||||
`^${ROUTE.HOME}$`,
|
||||
ROUTE.LOGIN,
|
||||
ROUTE.SIGN_UP,
|
||||
ROUTE.FORGOT,
|
||||
ROUTE.RESET,
|
||||
`^${ROUTE.COURSE}/.*`,
|
||||
];
|
||||
|
||||
export const ROUTES_TO_HIDE_NAV = [
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { PUBLIC_ROUTES } from '../../constants/routes';
|
||||
|
||||
export default (route) => {
|
||||
return PUBLIC_ROUTES.some((publicRoute) => {
|
||||
const regex = new RegExp(publicRoute, 'g');
|
||||
return regex.test(route);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user