fix: Logto loop infinito callback URL exacta

This commit is contained in:
2026-04-20 17:09:31 +00:00
parent db559f4581
commit d9e79fc771

View File

@@ -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 = `<div style="padding: 20px; color: red;"><h1>Erro de Autenticação Logto</h1><p>${error.message}</p></div>`;
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;
}