diff --git a/src/client/context/AuthContext.tsx b/src/client/context/AuthContext.tsx index f39a0fe..e0097b0 100644 --- a/src/client/context/AuthContext.tsx +++ b/src/client/context/AuthContext.tsx @@ -25,27 +25,45 @@ export const AuthProvider: React.FC = ({ children }) => { const [appUser, setAppUser] = useState(null); useEffect(() => { - const storedUser = getUser(); + const storedUser = localStorage.getItem('gpi_user'); if (storedUser) { - setAppUser({ ...defaultUser, ...storedUser, role: storedUser.role as UserRole }); - } else { - setAppUser(defaultUser); + try { + setAppUser(JSON.parse(storedUser)); + } catch (e) { + console.error("Error parsing stored user", e); + } } setApiOrganizationId(DEFAULT_ORGANIZATION_ID, DEFAULT_ORGANIZATION_NAME); }, []); - const isDeveloper = useCallback(() => false, []); - const isAdmin = useCallback(() => true, []); - const isUser = useCallback(() => true, []); - const isGuest = useCallback(() => false, []); - const canEdit = useCallback(() => true, []); + const signInWithPassword = async (password: string): Promise => { + if (password === '@@Gi05Br;;') { + const adminUser: AppUser = { + ...defaultUser, + id: 'admin-001', + email: 'admtracksteel@gmail.com', + name: 'Administrator / DEV', + role: 'admin' + }; + setAppUser(adminUser); + localStorage.setItem('gpi_user', JSON.stringify(adminUser)); + return true; + } + return false; + }; + + const isDeveloper = useCallback(() => appUser?.email === 'admtracksteel@gmail.com', [appUser]); + const isAdmin = useCallback(() => appUser?.role === 'admin' || appUser?.email === 'admtracksteel@gmail.com', [appUser]); + const isUser = useCallback(() => !!appUser, [appUser]); + const isGuest = useCallback(() => !appUser, [appUser]); + const canEdit = useCallback(() => isAdmin(), [isAdmin]); const refetchUser = useCallback(async () => {}, []); const value = useMemo(() => ({ appUser, isLoading: false, - isSignedIn: true, + isSignedIn: !!appUser, error: null, isAdmin, isUser, @@ -53,7 +71,8 @@ export const AuthProvider: React.FC = ({ children }) => { isDeveloper, canEdit, refetchUser, - }), [appUser, isAdmin, isUser, isGuest, isDeveloper, canEdit, refetchUser]); + signInWithPassword + }), [appUser, isAdmin, isUser, isGuest, isDeveloper, canEdit, refetchUser, signInWithPassword]); return ( diff --git a/src/client/context/AuthContextType.ts b/src/client/context/AuthContextType.ts index 7529430..e4feb18 100644 --- a/src/client/context/AuthContextType.ts +++ b/src/client/context/AuthContextType.ts @@ -12,6 +12,7 @@ export interface AuthContextType { isDeveloper: () => boolean; canEdit: () => boolean; refetchUser: () => Promise; + signInWithPassword: (password: string) => Promise; } export const AuthContext = createContext(undefined); diff --git a/src/client/pages/Login.tsx b/src/client/pages/Login.tsx index 3ba3578..3c67157 100644 --- a/src/client/pages/Login.tsx +++ b/src/client/pages/Login.tsx @@ -1,13 +1,32 @@ -import { Hammer } from "lucide-react"; -import { useLogto } from "@logto/react"; - -const CALLBACK_URL = import.meta.env.VITE_LOGTO_CALLBACK_URL || `${window.location.origin}/callback`; +import React, { useState } from 'react'; +import { Hammer, Lock, ShieldCheck } from "lucide-react"; +import { useAuth } from '../context/useAuth'; +import { useNavigate } from 'react-router-dom'; export const Login = () => { - const { signIn } = useLogto(); + const [password, setPassword] = useState(''); + const [error, setError] = useState(''); + const [loading, setLoading] = useState(false); + const { signInWithPassword } = useAuth(); + const navigate = useNavigate(); - const handleLogin = () => { - signIn(CALLBACK_URL); + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setError(''); + setLoading(true); + + try { + const success = await signInWithPassword(password); + if (success) { + navigate('/'); + } else { + setError('Senha incorreta. Acesso negado.'); + } + } catch (err) { + setError('Erro ao processar login.'); + } finally { + setLoading(false); + } }; return ( @@ -19,32 +38,54 @@ export const Login = () => {
{/* Logo Area */}
-
+
G
-

GPI

-

Gestão de Pintura Industrial

+

GPI RESTRICT

+

Ambiente de Desenvolvimento

- {/* Login Button - Logto */} -
- + {/* Login Form */} +
+
+ +

Chave de Acesso

+
+ +
+
+ setPassword(e.target.value)} + className="w-full h-14 bg-surface-soft border border-border/40 rounded-2xl px-6 text-sm focus:ring-4 focus:ring-primary/10 focus:border-primary transition-all font-bold placeholder:font-medium tracking-widest text-center" + required + autoFocus + /> + {error &&

{error}

} +
+ + +
-
- - © 2026 GPI - Eficiência Industrial +
+ + Desenvolvimento Ativo