Redirect to login without token and not on a public route

This commit is contained in:
Rotimi Best
2023-07-07 18:31:22 +01:00
parent 450d37034f
commit 5fcb517c58
4 changed files with 24 additions and 2 deletions
+1 -1
View File
@@ -95,4 +95,4 @@
"linux": {},
"mac": {}
}
}
}
+12
View File
@@ -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 -1
View File
@@ -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);
});
};