From f1433884b429a61008dd8ed610b1dcd7aa5a7626 Mon Sep 17 00:00:00 2001 From: admtracksteel Date: Mon, 20 Apr 2026 19:42:26 +0000 Subject: [PATCH] fix: explicit redirect URI and clean env --- .env | 80 ------------------------------------------------- dist/index.html | 2 +- src/main.js | 38 ++++++++++++++++------- 3 files changed, 29 insertions(+), 91 deletions(-) diff --git a/.env b/.env index b5e8ab3..280b98f 100644 --- a/.env +++ b/.env @@ -1,83 +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 -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 -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 diff --git a/dist/index.html b/dist/index.html index c28cda9..1e1a93a 100644 --- a/dist/index.html +++ b/dist/index.html @@ -6,7 +6,7 @@ Otimizador de Corte - TSCUT - + diff --git a/src/main.js b/src/main.js index d45d4d1..ee589f3 100644 --- a/src/main.js +++ b/src/main.js @@ -10,7 +10,6 @@ document.head.appendChild(style); 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'], }); @@ -18,29 +17,48 @@ async function protectPage() { const urlParams = new URLSearchParams(window.location.search); const isCallback = urlParams.has('code') && urlParams.has('state'); + // Usar a origem exata sem assumir caminhos para evitar desvios no Logto const exactRedirectUri = window.location.origin + '/'; + + console.log('TSCUT Auth: Verificando estado...', { isCallback, origin: window.location.origin }); if (isCallback) { try { + console.log('TSCUT Auth: Processando callback...', exactRedirectUri); await logtoClient.handleSignInCallback(exactRedirectUri); + console.log('TSCUT Auth: Login bem sucedido!'); window.location.assign('/'); } catch (error) { style.remove(); - document.body.innerHTML = `

Erro de Autenticação Logto

${error.message}

`; + document.body.innerHTML = ` +
+

Erro de Autenticação Logto

+

${error.message}

+
+

Dica: Se você estiver vendo "Missing state", verifique se os cookies e o armazenamento local estão habilitados para este site.

+ +
`; console.error('Falha no callback do Logto:', error); } return; } - const isAuthenticated = await logtoClient.isAuthenticated(); - if (!isAuthenticated) { - await logtoClient.signIn(exactRedirectUri); - return; - } + try { + const isAuthenticated = await logtoClient.isAuthenticated(); + if (!isAuthenticated) { + console.log('TSCUT Auth: Não autenticado. Redirecionando para login...'); + await logtoClient.signIn(exactRedirectUri); + return; + } - // Se chegou aqui, está logado. Mostramos o app. - style.remove(); - console.log('TSCUT: Acesso autorizado.'); + // Se chegou aqui, está logado. Mostramos o app. + style.remove(); + console.log('TSCUT: Acesso autorizado.'); + } catch (err) { + console.error('Erro ao verificar autenticação:', err); + // Em caso de erro na verificação, tentamos o login novamente + await logtoClient.signIn(exactRedirectUri); + } } // Execução imediata