feat: implement real user login state and fix profile view
All checks were successful
Build and Deploy / build-and-push (push) Successful in 2m12s

This commit is contained in:
Cauê Faleiros
2026-02-25 11:59:53 -03:00
parent a175315437
commit 9f047ece86
6 changed files with 68 additions and 40 deletions

View File

@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Hexagon, Lock, Mail, ArrowRight, Loader2, Info } from 'lucide-react';
import { USERS } from '../constants';
import { getUsers } from '../services/dataService';
export const Login: React.FC = () => {
const navigate = useNavigate();
@@ -10,22 +10,21 @@ export const Login: React.FC = () => {
const [password, setPassword] = useState('password');
const [error, setError] = useState('');
const handleLogin = (e: React.FormEvent) => {
const handleLogin = async (e: React.FormEvent) => {
e.preventDefault();
setIsLoading(true);
setError('');
// Simulate API call and validation
setTimeout(() => {
const user = USERS.find(u => u.email.toLowerCase() === email.toLowerCase());
try {
// Simplified auth for demo: fetch users and match email
const users = await getUsers('all');
const user = users.find(u => u.email.toLowerCase() === email.toLowerCase());
if (user) {
// Mock Login: Save to local storage
localStorage.setItem('ctms_user_id', user.id);
localStorage.setItem('ctms_tenant_id', user.tenant_id);
setIsLoading(false);
// Redirect based on role
if (user.role === 'super_admin') {
navigate('/super-admin');
} else {
@@ -33,9 +32,13 @@ export const Login: React.FC = () => {
}
} else {
setIsLoading(false);
setError('Usuário não encontrado. Tente lidya@fasto.com ou root@system.com');
setError('Usuário não encontrado.');
}
}, 1000);
} catch (err) {
console.error("Login error:", err);
setIsLoading(false);
setError('Erro ao conectar ao servidor.');
}
};
const fillCredentials = (type: 'admin' | 'super') => {