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() {
|
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) {
|
if (isCallback) {
|
||||||
try {
|
try {
|
||||||
await logtoClient.handleSignInCallback(window.location.href);
|
await logtoClient.handleSignInCallback(exactRedirectUri);
|
||||||
window.location.assign('/');
|
window.location.assign('/');
|
||||||
} catch (error) {
|
} 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);
|
console.error('Falha no callback do Logto:', error);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -29,7 +34,7 @@ async function protectPage() {
|
|||||||
|
|
||||||
const isAuthenticated = await logtoClient.isAuthenticated();
|
const isAuthenticated = await logtoClient.isAuthenticated();
|
||||||
if (!isAuthenticated) {
|
if (!isAuthenticated) {
|
||||||
await logtoClient.signIn(window.location.origin);
|
await logtoClient.signIn(exactRedirectUri);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user