photum/contexts/AuthContext.tsx
João Vitor 1caeddc72c feat: Initialize PhotumManager project structure
This commit sets up the foundational project structure for PhotumManager. It includes:
- Initializing a new React project with Vite.
- Configuring essential dependencies such as React, Lucide React, and the Google Generative AI SDK.
- Setting up TypeScript and Vite configurations for optimal development.
- Defining core application metadata and initial type definitions for users and events.
- Establishing basic styling and font configurations in `index.html` with Tailwind CSS.
- Adding a `.gitignore` file to manage project dependencies and build artifacts.
- Updating the README with instructions for local development.
2025-11-25 11:02:25 -03:00

76 lines
1.9 KiB
TypeScript

import React, { createContext, useContext, useState, ReactNode } from 'react';
import { User, UserRole } from '../types';
// Mock Users Database
const MOCK_USERS: User[] = [
{
id: 'superadmin-1',
name: 'Dev Admin',
email: 'admin@photum.com',
role: UserRole.SUPERADMIN,
avatar: 'https://i.pravatar.cc/150?u=admin'
},
{
id: 'owner-1',
name: 'Carlos CEO',
email: 'empresa@photum.com',
role: UserRole.BUSINESS_OWNER,
avatar: 'https://i.pravatar.cc/150?u=ceo'
},
{
id: 'photographer-1',
name: 'Ana Lente',
email: 'foto@photum.com',
role: UserRole.PHOTOGRAPHER,
avatar: 'https://i.pravatar.cc/150?u=photo'
},
{
id: 'client-1',
name: 'Juliana Noiva',
email: 'cliente@photum.com',
role: UserRole.EVENT_OWNER,
avatar: 'https://i.pravatar.cc/150?u=client'
}
];
interface AuthContextType {
user: User | null;
login: (email: string) => Promise<boolean>;
logout: () => void;
availableUsers: User[]; // Helper for the login screen demo
}
const AuthContext = createContext<AuthContextType | undefined>(undefined);
export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
const [user, setUser] = useState<User | null>(null);
const login = async (email: string) => {
// Simulate API call
await new Promise(resolve => setTimeout(resolve, 800));
const foundUser = MOCK_USERS.find(u => u.email === email);
if (foundUser) {
setUser(foundUser);
return true;
}
return false;
};
const logout = () => {
setUser(null);
};
return (
<AuthContext.Provider value={{ user, login, logout, availableUsers: MOCK_USERS }}>
{children}
</AuthContext.Provider>
);
};
export const useAuth = () => {
const context = useContext(AuthContext);
if (!context) throw new Error('useAuth must be used within an AuthProvider');
return context;
};