first commit

This commit is contained in:
Abdelrahman Abdallah
2026-04-01 21:51:49 +02:00
commit 27aff5611b
151 changed files with 10858 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
import React, { createContext, useState, useContext } from 'react';
const AuthContext = createContext();
export const useAuth = () => {
const context = useContext(AuthContext);
if (!context) {
throw new Error('useAuth must be used within an AuthProvider');
}
return context;
};
export const AuthProvider = ({ children }) => {
const [user, setUser] = useState(null);
const login = (userData) => {
setUser(userData);
localStorage.setItem('user', JSON.stringify(userData));
};
const logout = () => {
setUser(null);
localStorage.removeItem('user');
};
const value = {
user,
login,
logout
};
return (
<AuthContext.Provider value={value}>
{children}
</AuthContext.Provider>
);
};