Redirect to login without token and not on a public route
This commit is contained in:
+1
-1
@@ -95,4 +95,4 @@
|
|||||||
"linux": {},
|
"linux": {},
|
||||||
"mac": {}
|
"mac": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
isQuizPage,
|
isQuizPage,
|
||||||
} from '../utils/functions/app';
|
} from '../utils/functions/app';
|
||||||
import showAppsSideBar from '../utils/functions/showAppsSideBar';
|
import showAppsSideBar from '../utils/functions/showAppsSideBar';
|
||||||
|
import isPublicRoute from '../utils/functions/routes/isPublicRoute';
|
||||||
import { user, profile } from '../utils/store/user';
|
import { user, profile } from '../utils/store/user';
|
||||||
import { getSupabase } from '../utils/functions/supabase';
|
import { getSupabase } from '../utils/functions/supabase';
|
||||||
import { isMobile } from '../utils/store/useMobile';
|
import { isMobile } from '../utils/store/useMobile';
|
||||||
@@ -194,6 +195,17 @@
|
|||||||
|
|
||||||
handleResize();
|
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(
|
const { data: authListener } = supabase.auth.onAuthStateChange(
|
||||||
(event, session) => {
|
(event, session) => {
|
||||||
// Log key events
|
// Log key events
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ export const ROUTE = {
|
|||||||
DASHBOARD: '/dashboard',
|
DASHBOARD: '/dashboard',
|
||||||
ONBOARDING: '/onboarding',
|
ONBOARDING: '/onboarding',
|
||||||
COURSES: '/courses',
|
COURSES: '/courses',
|
||||||
|
COURSE: '/course',
|
||||||
LOGIN: '/login',
|
LOGIN: '/login',
|
||||||
SIGN_UP: '/signup',
|
SIGN_UP: '/signup',
|
||||||
PROFILE: '/profile',
|
PROFILE: '/profile',
|
||||||
@@ -14,11 +15,12 @@ export const ROUTE = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const PUBLIC_ROUTES = [
|
export const PUBLIC_ROUTES = [
|
||||||
ROUTE.HOME,
|
`^${ROUTE.HOME}$`,
|
||||||
ROUTE.LOGIN,
|
ROUTE.LOGIN,
|
||||||
ROUTE.SIGN_UP,
|
ROUTE.SIGN_UP,
|
||||||
ROUTE.FORGOT,
|
ROUTE.FORGOT,
|
||||||
ROUTE.RESET,
|
ROUTE.RESET,
|
||||||
|
`^${ROUTE.COURSE}/.*`,
|
||||||
];
|
];
|
||||||
|
|
||||||
export const ROUTES_TO_HIDE_NAV = [
|
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