upgrade: modernização automatizada Logto_Supa
This commit is contained in:
44
src/main.js
44
src/main.js
@@ -1,3 +1,47 @@
|
||||
|
||||
// --- LOGTO AUTH GUARD ---
|
||||
import LogtoClient from '@logto/browser';
|
||||
|
||||
// Escondemos o app imediatamente
|
||||
const style = document.createElement('style');
|
||||
style.innerHTML = 'body { display: none !important; }';
|
||||
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'],
|
||||
});
|
||||
|
||||
async function protectPage() {
|
||||
const isCallback = window.location.pathname.includes('callback');
|
||||
|
||||
if (isCallback) {
|
||||
try {
|
||||
await logtoClient.handleSignInCallback(window.location.href);
|
||||
window.location.assign('/');
|
||||
} catch (error) {
|
||||
console.error('Falha no callback do Logto:', error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const isAuthenticated = await logtoClient.isAuthenticated();
|
||||
if (!isAuthenticated) {
|
||||
await logtoClient.signIn(window.location.origin);
|
||||
return;
|
||||
}
|
||||
|
||||
// Se chegou aqui, está logado. Mostramos o app.
|
||||
style.remove();
|
||||
console.log('TSCUT: Acesso autorizado.');
|
||||
}
|
||||
|
||||
// Execução imediata
|
||||
protectPage();
|
||||
// -------------------------
|
||||
|
||||
import * as XLSX from 'xlsx';
|
||||
import Papa from 'papaparse';
|
||||
import './style.css';
|
||||
|
||||
Reference in New Issue
Block a user