feat: initial project setup with frontend mockup
- Docker Compose setup with nginx reverse proxy and frontend service - React + Vite + Tailwind CSS configuration - Complete mockup of all application views: - Authentication (login/register) - Events list and selection - Event chat with matchmaking - 1:1 private chat with WebRTC P2P video transfer mockup - Partner rating system - Collaboration history - Mock data for users, events, messages, matches, and ratings - All UI text and messages in English - Project documentation (CONTEXT.md, TODO.md, README.md, QUICKSTART.md)
This commit is contained in:
70
frontend/src/contexts/AuthContext.jsx
Normal file
70
frontend/src/contexts/AuthContext.jsx
Normal file
@@ -0,0 +1,70 @@
|
||||
import { createContext, useContext, useState, useEffect } from 'react';
|
||||
import { mockCurrentUser } from '../mocks/users';
|
||||
|
||||
const AuthContext = createContext(null);
|
||||
|
||||
export const useAuth = () => {
|
||||
const context = useContext(AuthContext);
|
||||
if (!context) {
|
||||
throw new Error('useAuth must be used within AuthProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
|
||||
export const AuthProvider = ({ children }) => {
|
||||
const [user, setUser] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
// Check if user is logged in (from localStorage)
|
||||
const storedUser = localStorage.getItem('user');
|
||||
if (storedUser) {
|
||||
setUser(JSON.parse(storedUser));
|
||||
}
|
||||
setLoading(false);
|
||||
}, []);
|
||||
|
||||
const login = async (email, password) => {
|
||||
// Mock login - w przyszłości będzie API call
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
const userData = mockCurrentUser;
|
||||
setUser(userData);
|
||||
localStorage.setItem('user', JSON.stringify(userData));
|
||||
resolve(userData);
|
||||
}, 500);
|
||||
});
|
||||
};
|
||||
|
||||
const register = async (username, email, password) => {
|
||||
// Mock register - w przyszłości będzie API call
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
const userData = {
|
||||
...mockCurrentUser,
|
||||
username,
|
||||
email,
|
||||
};
|
||||
setUser(userData);
|
||||
localStorage.setItem('user', JSON.stringify(userData));
|
||||
resolve(userData);
|
||||
}, 500);
|
||||
});
|
||||
};
|
||||
|
||||
const logout = () => {
|
||||
setUser(null);
|
||||
localStorage.removeItem('user');
|
||||
};
|
||||
|
||||
const value = {
|
||||
user,
|
||||
loading,
|
||||
login,
|
||||
register,
|
||||
logout,
|
||||
isAuthenticated: !!user,
|
||||
};
|
||||
|
||||
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
|
||||
};
|
||||
Reference in New Issue
Block a user