import React, { createContext, useContext, useState } from 'react'; const AuthContext = createContext(null); export const AuthProvider = ({ children }) => { const [token, setToken] = useState(localStorage.getItem('token')); const login = (newToken) => { setToken(newToken); localStorage.setItem('token', newToken); }; const logout = () => { setToken(null); localStorage.removeItem('token'); }; return ( {children} ); }; export const useAuth = () => { const context = useContext(AuthContext); if (!context) { throw new Error('useAuth must be used within an AuthProvider'); } return context; };