fix: robust static callback and debug telemetry
This commit is contained in:
2
dist/index.html
vendored
2
dist/index.html
vendored
@@ -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-DkgqtOrP.js"></script>
|
<script type="module" crossorigin src="/assets/index-DBmQnaAQ.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-CpYIvPGq.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-CpYIvPGq.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|||||||
47
src/main.js
47
src/main.js
@@ -17,28 +17,47 @@ async function protectPage() {
|
|||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const isCallback = urlParams.has('code') && urlParams.has('state');
|
const isCallback = urlParams.has('code') && urlParams.has('state');
|
||||||
|
|
||||||
// Usar a origem exata sem assumir caminhos para evitar desvios no Logto
|
// Forçar a URI exata registrada no Logto para evitar variações de origin
|
||||||
const exactRedirectUri = window.location.origin + '/';
|
const exactRedirectUri = 'https://tscut.reifonas.cloud/';
|
||||||
|
|
||||||
console.log('TSCUT Auth: Verificando estado...', { isCallback, origin: window.location.origin });
|
console.log('TSCUT Auth: Inicializando...', {
|
||||||
|
isCallback,
|
||||||
|
href: window.location.href,
|
||||||
|
storageKeys: Object.keys(sessionStorage).filter(k => k.includes('logto'))
|
||||||
|
});
|
||||||
|
|
||||||
if (isCallback) {
|
if (isCallback) {
|
||||||
try {
|
try {
|
||||||
console.log('TSCUT Auth: Processando callback...', exactRedirectUri);
|
console.log('TSCUT Auth: Processando callback com URI:', exactRedirectUri);
|
||||||
|
|
||||||
|
// Pequeno delay para garantir que o storage foi persistido pelo navegador
|
||||||
|
await new Promise(r => setTimeout(r, 100));
|
||||||
|
|
||||||
await logtoClient.handleSignInCallback(exactRedirectUri);
|
await logtoClient.handleSignInCallback(exactRedirectUri);
|
||||||
console.log('TSCUT Auth: Login bem sucedido!');
|
console.log('TSCUT Auth: Login OK! Redirecionando...');
|
||||||
window.location.assign('/');
|
window.location.assign('/');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
style.remove();
|
style.remove();
|
||||||
|
const logtoState = sessionStorage.getItem(`logto:${import.meta.env.VITE_LOGTO_APP_ID}:state`);
|
||||||
|
|
||||||
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>Erro de Autenticação Logto</h1>
|
<h1 style="color: white; border-bottom: 2px solid #ff5555; padding-bottom: 10px;">Falha na Identificação Industrial</h1>
|
||||||
<p style="font-size: 1.2em;">${error.message}</p>
|
<p style="font-size: 1.2em; background: #330000; padding: 15px; border-radius: 5px;">
|
||||||
<hr style="border-color: #333;">
|
Erro: ${error.message}
|
||||||
<p><strong>Dica:</strong> Se você estiver vendo "Missing state", verifique se os cookies e o armazenamento local estão habilitados para este site.</p>
|
</p>
|
||||||
<button onclick="window.location.assign('/')" style="padding: 10px 20px; cursor: pointer;">Tentar Novamente</button>
|
<div style="background: #222; padding: 15px; border-radius: 5px; margin-top: 20px; font-family: monospace; font-size: 0.9em; color: #aaa;">
|
||||||
|
<strong>Debug Info:</strong><br>
|
||||||
|
- AppID: ${import.meta.env.VITE_LOGTO_APP_ID}<br>
|
||||||
|
- URI Usada: ${exactRedirectUri}<br>
|
||||||
|
- State na URL: ${urlParams.get('state')?.substring(0, 10)}...<br>
|
||||||
|
- State no Storage: ${logtoState ? 'Presente' : 'AUSENTE'}<br>
|
||||||
|
</div>
|
||||||
|
<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;">
|
||||||
|
🔄 Tentar Novamente (Limpar Sessão)
|
||||||
|
</button>
|
||||||
</div>`;
|
</div>`;
|
||||||
console.error('Falha no callback do Logto:', error);
|
console.error('Falha crítica no callback:', error);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -46,17 +65,15 @@ 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 para login...');
|
console.log('TSCUT Auth: Iniciando fluxo de login...');
|
||||||
await logtoClient.signIn(exactRedirectUri);
|
await logtoClient.signIn(exactRedirectUri);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Se chegou aqui, está logado. Mostramos o app.
|
|
||||||
style.remove();
|
style.remove();
|
||||||
console.log('TSCUT: Acesso autorizado.');
|
console.log('TSCUT: Acesso autorizado.');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Erro ao verificar autenticação:', err);
|
console.error('Erro na verificação de sessão:', err);
|
||||||
// Em caso de erro na verificação, tentamos o login novamente
|
|
||||||
await logtoClient.signIn(exactRedirectUri);
|
await logtoClient.signIn(exactRedirectUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user