feat: wire real auth — login returns user profile with role from platform, remove mock users and role selector tabs

This commit is contained in:
2026-03-18 10:42:54 +05:30
parent 832fa31597
commit 66ad398b81
4 changed files with 82 additions and 72 deletions

View File

@@ -20,24 +20,16 @@ const features = [
},
];
type RoleTab = 'executive' | 'cc-agent' | 'admin';
export const LoginPage = () => {
const { login, setRole } = useAuth();
const { loginWithUser } = useAuth();
const navigate = useNavigate();
const [activeTab, setActiveTab] = useState<RoleTab>('executive');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false);
const handleTabChange = (tab: RoleTab) => {
setActiveTab(tab);
setRole(tab);
setError(null);
};
const handleSubmit = async (event: React.FormEvent) => {
event.preventDefault();
setError(null);
@@ -50,8 +42,25 @@ export const LoginPage = () => {
setIsLoading(true);
try {
const { apiClient } = await import('@/lib/api-client');
await apiClient.login(email, password);
login();
const response = await apiClient.login(email, password);
// Build user from sidecar response
const u = response.user;
const firstName = u?.firstName ?? '';
const lastName = u?.lastName ?? '';
const name = `${firstName} ${lastName}`.trim() || email;
const initials = `${firstName[0] ?? ''}${lastName[0] ?? ''}`.toUpperCase() || email[0].toUpperCase();
loginWithUser({
id: u?.id,
name,
initials,
role: (u?.role ?? 'executive') as 'executive' | 'admin' | 'cc-agent',
email: u?.email ?? email,
avatarUrl: u?.avatarUrl,
platformRoles: u?.platformRoles,
});
navigate('/');
} catch (err: any) {
setError(err.message);
@@ -60,7 +69,6 @@ export const LoginPage = () => {
};
const handleGoogleSignIn = () => {
// TODO: implement Google OAuth via sidecar
setError('Google sign-in not yet configured');
};
@@ -138,30 +146,7 @@ export const LoginPage = () => {
<h2 className="text-display-xs font-bold text-primary font-display">Sign in to Helix Engage</h2>
<p className="mt-1 text-sm text-tertiary">Global Hospital</p>
{/* Role selector tabs */}
<div
className="mt-8 flex items-center gap-1 rounded-xl p-1 bg-secondary"
>
{([
{ key: 'executive' as const, label: 'Marketing Executive' },
{ key: 'cc-agent' as const, label: 'Call Center' },
{ key: 'admin' as const, label: 'Admin' },
]).map((tab) => (
<button
key={tab.key}
type="button"
onClick={() => handleTabChange(tab.key)}
className={[
'flex-1 rounded-lg px-3 py-2 text-sm font-semibold transition duration-300 ease-[cubic-bezier(0.4,0,0.2,1)]',
activeTab === tab.key
? 'bg-primary text-brand-secondary shadow-sm'
: 'text-tertiary hover:text-secondary',
].join(' ')}
>
{tab.label}
</button>
))}
</div>
{/* Role is determined by platform — no selector needed */}
{/* Google sign-in */}
<div className="mt-6">