fix: restore persistent storage and page reload
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">
|
||||
<link rel="icon" href="/logo.png" type="image/png">
|
||||
<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">
|
||||
</head>
|
||||
|
||||
|
||||
26
src/main.js
26
src/main.js
@@ -7,10 +7,20 @@ 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,
|
||||
scopes: ['openid', 'offline_access', 'profile', 'email', 'organizations'],
|
||||
storage: persistentStorage // CRÍTICO: localStorage forçado
|
||||
});
|
||||
|
||||
async function protectPage() {
|
||||
@@ -22,21 +32,17 @@ async function protectPage() {
|
||||
|
||||
if (isCallback) {
|
||||
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);
|
||||
|
||||
console.log('TSCUT Auth: Login bem sucedido!');
|
||||
// Limpa os parâmetros da URL para evitar erro no reload manual
|
||||
window.history.replaceState({}, document.title, redirectUri);
|
||||
|
||||
style.remove();
|
||||
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</h1>
|
||||
<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; 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
|
||||
</button>
|
||||
</div>`;
|
||||
@@ -48,7 +54,7 @@ async function protectPage() {
|
||||
try {
|
||||
const isAuthenticated = await logtoClient.isAuthenticated();
|
||||
if (!isAuthenticated) {
|
||||
console.log('TSCUT Auth: Não autenticado. Redirecionando...');
|
||||
console.log('TSCUT Auth: Redirecionando para login Logto...');
|
||||
await logtoClient.signIn(redirectUri);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user