fix: Logto loop infinito callback URL exacta
This commit is contained in:
11
src/main.js
11
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 = `<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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user