Private
Public Access
primeros cambios hechos para tener el multitenant
This commit is contained in:
1 parent
34ad4424f9
commit
4e082e8767
132 files changed
+6202
-762
No files matched your search
@@ -3,13 +3,22 @@
|
||||
import 'carbon-components-svelte/css/all.css';
|
||||
import favicon from '$lib/assets/favicon.svg';
|
||||
import { AUTH_CHANGE_EVENT, getToken } from '$lib/hooks/token';
|
||||
import { getCurrentUser } from '$lib/hooks/user';
|
||||
import { goto } from '$app/navigation';
|
||||
import { browser } from '$app/environment';
|
||||
import { page } from '$app/state';
|
||||
import { TokenRefresher } from '$lib/TokenRefresher.svelte';
|
||||
|
||||
let { children } = $props();
|
||||
let theme = 'g100'; // "white" | "g10" | "g80" | "g90" | "g100"
|
||||
let token = $state(getToken());
|
||||
|
||||
const RUTAS_PUBLICAS = new Set(['/', '/login', '/register']);
|
||||
|
||||
function esRutaPublica(path: string): boolean {
|
||||
return RUTAS_PUBLICAS.has(path) || path.startsWith('/invitaciones/');
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
document.documentElement.setAttribute('theme', theme);
|
||||
});
|
||||
@@ -28,6 +37,30 @@
|
||||
};
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (!browser) return;
|
||||
|
||||
const path = page.url.pathname;
|
||||
|
||||
if (!token && !esRutaPublica(path)) {
|
||||
const destino = path === '/' ? '' : `?next=${encodeURIComponent(path + page.url.search)}`;
|
||||
void goto(`/login${destino}`, { replaceState: true });
|
||||
return;
|
||||
}
|
||||
|
||||
if (token && (path === '/login' || path === '/register')) {
|
||||
void goto('/menu', { replaceState: true });
|
||||
return;
|
||||
}
|
||||
|
||||
if (token && path !== '/cambiar-contraseña') {
|
||||
const usuario = getCurrentUser();
|
||||
if (usuario?.debe_cambiar_password) {
|
||||
void goto('/cambiar-contraseña', { replaceState: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let _refresher: TokenRefresher;
|
||||
|
||||
$effect(() => {
|
||||
|
||||
Reference in new issue
Block a user