fix: restore persistent storage and page reload

This commit is contained in:
2026-04-20 21:23:40 +00:00
parent 7e73398e5b
commit e3e7646204
2 changed files with 17 additions and 11 deletions

2
dist/index.html vendored
View File

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

View File

@@ -7,10 +7,20 @@ const style = document.createElement('style');
style.innerHTML = 'body { display: none !important; }'; style.innerHTML = 'body { display: none !important; }';
document.head.appendChild(style); document.head.appendChild(style);
// Implementação de Storage Persistente para evitar perda de sessão em cross-domain
const persistentStorage = {
getItem: (key) => localStorage.getItem(key),
setItem: (key, value) => {
try { localStorage.setItem(key, value); } catch (e) { console.error('Storage error', e); }
},
removeItem: (key) => localStorage.removeItem(key),
};
const logtoClient = new LogtoClient({ const logtoClient = new LogtoClient({
endpoint: import.meta.env.VITE_LOGTO_ENDPOINT, endpoint: import.meta.env.VITE_LOGTO_ENDPOINT,
appId: import.meta.env.VITE_LOGTO_APP_ID, appId: import.meta.env.VITE_LOGTO_APP_ID,
scopes: ['openid', 'offline_access', 'profile', 'email', 'organizations'], scopes: ['openid', 'offline_access', 'profile', 'email', 'organizations'],
storage: persistentStorage // CRÍTICO: localStorage forçado
}); });
async function protectPage() { async function protectPage() {
@@ -22,21 +32,17 @@ async function protectPage() {
if (isCallback) { if (isCallback) {
try { try {
// CRÍTICO: handleSignInCallback precisa da URL COMPLETA para extrair o ?code= e &state= // Logto DEVE receber a URL completa com parâmetros para extrair o state
await logtoClient.handleSignInCallback(window.location.href); await logtoClient.handleSignInCallback(window.location.href);
console.log('TSCUT Auth: Login bem sucedido. Recarregando app...');
console.log('TSCUT Auth: Login bem sucedido!'); window.location.assign('/');
// Limpa os parâmetros da URL para evitar erro no reload manual
window.history.replaceState({}, document.title, redirectUri);
style.remove();
} catch (error) { } catch (error) {
style.remove(); style.remove();
document.body.innerHTML = ` document.body.innerHTML = `
<div style="padding: 20px; color: #ff5555; background: #1a1a1a; min-height: 100vh; font-family: sans-serif;"> <div style="padding: 20px; color: #ff5555; background: #1a1a1a; min-height: 100vh; font-family: sans-serif;">
<h1>Falha na Autenticação</h1> <h1>Falha na Autenticação Industrial</h1>
<p style="font-size: 1.2em;">Erro: ${error.message}</p> <p style="font-size: 1.2em;">Erro: ${error.message}</p>
<button onclick="window.location.assign('/')" style="margin-top: 20px; padding: 12px 25px; cursor: pointer; background: #444; color: white; border: none; border-radius: 5px; font-weight: bold;"> <button onclick="window.location.assign('/')" style="margin-top: 20px; padding: 12px 25px; cursor: pointer;">
Tentar Novamente Tentar Novamente
</button> </button>
</div>`; </div>`;
@@ -48,7 +54,7 @@ async function protectPage() {
try { try {
const isAuthenticated = await logtoClient.isAuthenticated(); const isAuthenticated = await logtoClient.isAuthenticated();
if (!isAuthenticated) { if (!isAuthenticated) {
console.log('TSCUT Auth: Não autenticado. Redirecionando...'); console.log('TSCUT Auth: Redirecionando para login Logto...');
await logtoClient.signIn(redirectUri); await logtoClient.signIn(redirectUri);
return; return;
} }