added server

This commit is contained in:
2025-10-20 06:32:14 -04:00
parent df7c275929
commit f2cf309d97
43 changed files with 1520 additions and 1 deletions

View File

@@ -0,0 +1,43 @@
import {useState, useEffect} from 'react';
import type {User} from '@/types';
export const useAuth = () => {
const [user, setUser] = useState<User | null>(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 = (email: string, password: string) => {
// Simple authentication (in production, use a real backend)
if (email && password) {
const newUser: User = {
email,
isAuthenticated: true
};
localStorage.setItem('user', JSON.stringify(newUser));
setUser(newUser);
return true;
}
return false;
};
const logout = () => {
localStorage.removeItem('user');
setUser(null);
};
return {
user,
loading,
login,
logout,
isAuthenticated: !!user?.isAuthenticated
};
};