Migracao Logto + Supabase - backend e frontend atualizados para nova autenticação
This commit is contained in:
@@ -1,47 +1,57 @@
|
||||
import { createRoot } from 'react-dom/client'
|
||||
|
||||
import { ClerkProvider } from '@clerk/clerk-react'
|
||||
import { ptBR } from '@clerk/localizations'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
|
||||
const PUBLISHABLE_KEY = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY
|
||||
const LOGTO_URL = import.meta.env.VITE_LOGTO_URL || 'https://logto-admin-bzlued1boxl3t8ewsyn99an9.187.77.227.172.sslip.io';
|
||||
const APP_ID = import.meta.env.VITE_LOGTO_APP_ID || 'gpi-app-001';
|
||||
|
||||
if (!PUBLISHABLE_KEY) {
|
||||
throw new Error("Missing Publishable Key")
|
||||
const redirectUrl = `${window.location.origin}/auth/callback`;
|
||||
|
||||
function generateRandomString(length: number) {
|
||||
const array = new Uint8Array(length);
|
||||
crypto.getRandomValues(array);
|
||||
return Array.from(array, (byte) => byte.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
|
||||
function storeState(state: string) {
|
||||
sessionStorage.setItem('logto_oauth_state', state);
|
||||
}
|
||||
|
||||
export function login() {
|
||||
const state = generateRandomString(21);
|
||||
storeState(state);
|
||||
|
||||
const params = new URLSearchParams({
|
||||
client_id: APP_ID,
|
||||
redirect_uri: redirectUrl,
|
||||
response_type: 'code',
|
||||
scope: 'openid profile email',
|
||||
state: state
|
||||
});
|
||||
|
||||
window.location.href = `${LOGTO_URL}/oidc/auth?${params.toString()}`;
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
sessionStorage.removeItem('logto_token');
|
||||
sessionStorage.removeItem('logto_user');
|
||||
window.location.href = '/';
|
||||
}
|
||||
|
||||
export function getToken() {
|
||||
return sessionStorage.getItem('logto_token');
|
||||
}
|
||||
|
||||
export function getUser() {
|
||||
const user = sessionStorage.getItem('logto_user');
|
||||
return user ? JSON.parse(user) : null;
|
||||
}
|
||||
|
||||
export function setUser(token: string, user: any) {
|
||||
sessionStorage.setItem('logto_token', token);
|
||||
sessionStorage.setItem('logto_user', JSON.stringify(user));
|
||||
}
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<ClerkProvider
|
||||
publishableKey={PUBLISHABLE_KEY}
|
||||
afterSignOutUrl="/"
|
||||
localization={ptBR}
|
||||
appearance={{
|
||||
variables: {
|
||||
colorPrimary: '#fb923c', // Cor primária do GPI (Laranja)
|
||||
colorBackground: '#ffffff',
|
||||
colorText: '#1c1917',
|
||||
colorTextSecondary: '#57534e',
|
||||
borderRadius: '0.75rem',
|
||||
},
|
||||
elements: {
|
||||
card: "shadow-none border-0 bg-transparent", // Deixamos o container da página controlar o card
|
||||
navbar: "hidden",
|
||||
headerTitle: "text-2xl font-bold tracking-tight",
|
||||
headerSubtitle: "text-text-muted font-medium",
|
||||
formButtonPrimary: "bg-primary hover:bg-primary/90 text-white font-bold py-3 rounded-xl transition-all shadow-lg shadow-primary/20",
|
||||
socialButtonsBlockButton: "bg-white hover:bg-surface-hover border-border/40 text-text-main font-semibold transition-all duration-300 rounded-xl",
|
||||
footerActionLink: "text-primary hover:text-primary/80 font-bold",
|
||||
formFieldInput: "bg-surface-soft border-border/40 focus:ring-2 focus:ring-primary/20 focus:border-primary rounded-xl",
|
||||
organizationSwitcherTrigger: "hover:bg-surface-hover transition-colors rounded-xl",
|
||||
organizationPreviewMainIdentifier: "font-bold",
|
||||
// Personalização específica para a lista de organizações que aparece na imagem
|
||||
organizationListPreview: "hover:bg-surface-soft rounded-xl transition-all p-3",
|
||||
organizationListCreateOrganizationButton: "text-primary font-bold hover:text-primary/80",
|
||||
}
|
||||
}}
|
||||
>
|
||||
<App />
|
||||
</ClerkProvider>,
|
||||
<App />
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user