Compare commits
14 Commits
1bfab35700
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 80464b9187 | |||
| e3e7646204 | |||
| 7e73398e5b | |||
| 643dbe1b34 | |||
| b83e87d541 | |||
| f1433884b4 | |||
| b939f09fa4 | |||
| d9e79fc771 | |||
| db559f4581 | |||
| 65fb2d8da8 | |||
| 481dd850eb | |||
| fcecf72749 | |||
| 4da39e34bc | |||
| 6479f6a4d6 |
38
.env
38
.env
@@ -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
2
dist/index.html
vendored
@@ -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>
|
||||
|
||||
|
||||
49
src/main.js
49
src/main.js
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user