fix: force localStorage for Logto persistence

This commit is contained in:
2026-04-20 20:11:04 +00:00
parent b83e87d541
commit 643dbe1b34
2 changed files with 11 additions and 3 deletions

2
dist/index.html vendored
View File

@@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="/logo.png" type="image/png">
<title>Otimizador de Corte - TSCUT</title>
<script type="module" crossorigin src="/assets/index-DBmQnaAQ.js"></script>
<script type="module" crossorigin src="/assets/index-B7sXKXk5.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-CpYIvPGq.css">
</head>

View File

@@ -7,10 +7,18 @@ const style = document.createElement('style');
style.innerHTML = 'body { display: none !important; }';
document.head.appendChild(style);
// Implementação de Storage Persistente para evitar perdas em redirecionamentos
const persistentStorage = {
getItem: (key) => localStorage.getItem(key),
setItem: (key, value) => localStorage.setItem(key, value),
removeItem: (key) => localStorage.removeItem(key),
};
const logtoClient = new LogtoClient({
endpoint: import.meta.env.VITE_LOGTO_ENDPOINT,
appId: import.meta.env.VITE_LOGTO_APP_ID,
scopes: ['openid', 'offline_access', 'profile', 'email', 'organizations'],
storage: persistentStorage, // Força o uso de localStorage
});
async function protectPage() {
@@ -23,7 +31,7 @@ async function protectPage() {
console.log('TSCUT Auth: Inicializando...', {
isCallback,
href: window.location.href,
storageKeys: Object.keys(sessionStorage).filter(k => k.includes('logto'))
storageKeys: Object.keys(localStorage).filter(k => k.includes('logto'))
});
if (isCallback) {
@@ -38,7 +46,7 @@ async function protectPage() {
window.location.assign('/');
} catch (error) {
style.remove();
const logtoState = sessionStorage.getItem(`logto:${import.meta.env.VITE_LOGTO_APP_ID}:state`);
const logtoState = localStorage.getItem(`logto:${import.meta.env.VITE_LOGTO_APP_ID}:state`);
document.body.innerHTML = `
<div style="padding: 20px; color: #ff5555; background: #1a1a1a; min-height: 100vh; font-family: sans-serif;">