fix: redirect to login on code change
This commit is contained in:
@@ -22,3 +22,15 @@ export const getSupabase = (config?: ConfigType) => {
|
|||||||
|
|
||||||
return supabase;
|
return supabase;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isSupabaseTokenInLocalStorage = () => {
|
||||||
|
for (let i = 0; i < localStorage.length; i++) {
|
||||||
|
const key = localStorage.key(i);
|
||||||
|
if (key === null) continue; // Skip if null (shouldn't happen)
|
||||||
|
if (/sb-[\w-]+-auth-token/.test(key)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
import showAppsSideBar from '$lib/utils/functions/showAppsSideBar';
|
import showAppsSideBar from '$lib/utils/functions/showAppsSideBar';
|
||||||
import isPublicRoute from '$lib/utils/functions/routes/isPublicRoute';
|
import isPublicRoute from '$lib/utils/functions/routes/isPublicRoute';
|
||||||
import { user, profile } from '$lib/utils/store/user';
|
import { user, profile } from '$lib/utils/store/user';
|
||||||
import { getSupabase } from '$lib/utils/functions/supabase';
|
import { getSupabase, isSupabaseTokenInLocalStorage } from '$lib/utils/functions/supabase';
|
||||||
import { isMobile } from '$lib/utils/store/useMobile';
|
import { isMobile } from '$lib/utils/store/useMobile';
|
||||||
import { ROUTE } from '$lib/utils/constants/routes';
|
import { ROUTE } from '$lib/utils/constants/routes';
|
||||||
import { getOrganizations } from '$lib/utils/services/org';
|
import { getOrganizations } from '$lib/utils/services/org';
|
||||||
@@ -220,7 +220,7 @@
|
|||||||
handleResize();
|
handleResize();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!localStorage.getItem(`sb-${PUBLIC_SUPABASE_PROJECT_REF}-auth-token`) &&
|
!isSupabaseTokenInLocalStorage() &&
|
||||||
!isPublicRoute($page.url.pathname)
|
!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);
|
||||||
|
|||||||
Reference in New Issue
Block a user