diff --git a/src/main.js b/src/main.js index 729fdc8..d45d4d1 100644 --- a/src/main.js +++ b/src/main.js @@ -15,13 +15,18 @@ const logtoClient = new LogtoClient({ }); 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'); + const exactRedirectUri = window.location.origin + '/'; + if (isCallback) { try { - await logtoClient.handleSignInCallback(window.location.href); + await logtoClient.handleSignInCallback(exactRedirectUri); window.location.assign('/'); } catch (error) { + style.remove(); + document.body.innerHTML = `

Erro de Autenticação Logto

${error.message}

`; console.error('Falha no callback do Logto:', error); } return; @@ -29,7 +34,7 @@ async function protectPage() { const isAuthenticated = await logtoClient.isAuthenticated(); if (!isAuthenticated) { - await logtoClient.signIn(window.location.origin); + await logtoClient.signIn(exactRedirectUri); return; }