mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage
synced 2026-04-11 18:28:15 +00:00
feat: add auth and data providers with mock data hooks
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
68
src/providers/auth-provider.tsx
Normal file
68
src/providers/auth-provider.tsx
Normal file
@@ -0,0 +1,68 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { createContext, useContext, useState } from 'react';
|
||||
|
||||
export type Role = 'executive' | 'admin';
|
||||
|
||||
type User = {
|
||||
name: string;
|
||||
initials: string;
|
||||
role: Role;
|
||||
email: string;
|
||||
};
|
||||
|
||||
type AuthContextType = {
|
||||
user: User;
|
||||
setRole: (role: Role) => void;
|
||||
isAdmin: boolean;
|
||||
isAuthenticated: boolean;
|
||||
login: () => void;
|
||||
logout: () => void;
|
||||
};
|
||||
|
||||
const USERS: Record<Role, User> = {
|
||||
admin: {
|
||||
name: 'Admin User',
|
||||
initials: 'AU',
|
||||
role: 'admin',
|
||||
email: 'admin@ramaiah.com',
|
||||
},
|
||||
executive: {
|
||||
name: 'Sanjay M.',
|
||||
initials: 'SM',
|
||||
role: 'executive',
|
||||
email: 'sanjay@ramaiah.com',
|
||||
},
|
||||
};
|
||||
|
||||
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||
|
||||
export const useAuth = (): AuthContextType => {
|
||||
const context = useContext(AuthContext);
|
||||
|
||||
if (context === undefined) {
|
||||
throw new Error('useAuth must be used within an AuthProvider');
|
||||
}
|
||||
|
||||
return context;
|
||||
};
|
||||
|
||||
interface AuthProviderProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export const AuthProvider = ({ children }: AuthProviderProps) => {
|
||||
const [role, setRole] = useState<Role>('executive');
|
||||
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||
|
||||
const user = USERS[role];
|
||||
const isAdmin = role === 'admin';
|
||||
|
||||
const login = () => setIsAuthenticated(true);
|
||||
const logout = () => setIsAuthenticated(false);
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={{ user, setRole, isAdmin, isAuthenticated, login, logout }}>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user