Compare commits

..

14 Commits

3 changed files with 40 additions and 49 deletions

38
.env
View File

@@ -1,41 +1,3 @@
# --- LOGTO_SUPA UPGRADE ---
VITE_LOGTO_ENDPOINT=https://logto-bzlued1boxl3t8ewsyn99an9.187.77.227.172.sslip.io
VITE_LOGTO_APP_ID=3whpc0jru4ka5nerinnuc
VITE_LOGTO_ORG_ID=b8dvrye4978k
VITE_SUPABASE_SCHEMA=TSCUT
# --- LOGTO_SUPA UPGRADE ---
VITE_LOGTO_ENDPOINT=https://logto-bzlued1boxl3t8ewsyn99an9.187.77.227.172.sslip.io
VITE_LOGTO_APP_ID=3whpc0jru4ka5nerinnuc
VITE_LOGTO_ORG_ID=4j7uhxlmia9e
VITE_SUPABASE_SCHEMA=TSCUT
# --- LOGTO_SUPA UPGRADE ---
VITE_LOGTO_ENDPOINT=https://logto-bzlued1boxl3t8ewsyn99an9.187.77.227.172.sslip.io
VITE_LOGTO_APP_ID=3whpc0jru4ka5nerinnuc
VITE_LOGTO_ORG_ID=4j7uhxlmia9e
VITE_SUPABASE_SCHEMA=TSCUT
# --- LOGTO_SUPA UPGRADE ---
VITE_LOGTO_ENDPOINT=https://logto-bzlued1boxl3t8ewsyn99an9.187.77.227.172.sslip.io
VITE_LOGTO_APP_ID=3whpc0jru4ka5nerinnuc
VITE_LOGTO_ORG_ID=4j7uhxlmia9e
VITE_SUPABASE_SCHEMA=TSCUT
# --- LOGTO_SUPA UPGRADE ---
VITE_LOGTO_ENDPOINT=https://logto-bzlued1boxl3t8ewsyn99an9.187.77.227.172.sslip.io
VITE_LOGTO_APP_ID=3whpc0jru4ka5nerinnuc
VITE_LOGTO_ORG_ID=4j7uhxlmia9e
VITE_SUPABASE_SCHEMA=TSCUT
# --- LOGTO_SUPA UPGRADE ---
VITE_LOGTO_ENDPOINT=https://logto-bzlued1boxl3t8ewsyn99an9.187.77.227.172.sslip.io
VITE_LOGTO_APP_ID=3whpc0jru4ka5nerinnuc
VITE_LOGTO_ORG_ID=4j7uhxlmia9e
VITE_SUPABASE_SCHEMA=TSCUT
# --- LOGTO_SUPA UPGRADE ---
VITE_LOGTO_ENDPOINT=https://logto-bzlued1boxl3t8ewsyn99an9.187.77.227.172.sslip.io
VITE_LOGTO_APP_ID=3whpc0jru4ka5nerinnuc
VITE_LOGTO_ORG_ID=4j7uhxlmia9e

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-DH8nqnYc.js"></script>
<script type="module" crossorigin src="/assets/index-CZqN6Z_L.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-CpYIvPGq.css">
</head>

View File

@@ -7,35 +7,64 @@ const style = document.createElement('style');
style.innerHTML = 'body { display: none !important; }';
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({
endpoint: import.meta.env.VITE_LOGTO_ENDPOINT,
appId: import.meta.env.VITE_LOGTO_APP_ID,
resource: 'https://default.logto.app/api',
scopes: ['openid', 'offline_access', 'profile', 'email', 'organizations'],
storage: persistentStorage // CRÍTICO: localStorage forçado
});
async function protectPage() {
const isCallback = window.location.pathname.includes('callback');
const urlParams = new URLSearchParams(window.location.search);
const isCallback = urlParams.has('code') && urlParams.has('state');
// A URI exata para a qual o Logto vai devolver o usuário
const redirectUri = window.location.origin + '/';
if (isCallback) {
try {
// Logto DEVE receber a URL completa com parâmetros para extrair o state
await logtoClient.handleSignInCallback(window.location.href);
console.log('TSCUT Auth: Login bem sucedido. Recarregando app...');
window.location.assign('/');
} catch (error) {
style.remove();
document.body.innerHTML = `
<div style="padding: 20px; color: #ff5555; background: #1a1a1a; min-height: 100vh; font-family: sans-serif;">
<h1>Falha na Autenticação Industrial</h1>
<p style="font-size: 1.2em;">Erro: ${error.message}</p>
<button onclick="window.location.assign('/')" style="margin-top: 20px; padding: 12px 25px; cursor: pointer;">
Tentar Novamente
</button>
</div>`;
console.error('Falha no callback do Logto:', error);
}
return;
}
const isAuthenticated = await logtoClient.isAuthenticated();
if (!isAuthenticated) {
await logtoClient.signIn(window.location.origin);
return;
}
try {
const isAuthenticated = await logtoClient.isAuthenticated();
if (!isAuthenticated) {
console.log('TSCUT Auth: Redirecionando para login Logto...');
await logtoClient.signIn(redirectUri);
return;
}
// Se chegou aqui, está logado. Mostramos o app.
style.remove();
console.log('TSCUT: Acesso autorizado.');
// Acesso permitido
style.remove();
} catch (err) {
console.error('Erro de autenticação:', err);
await logtoClient.signIn(redirectUri);
}
}
// Execução imediata