Add new frontend - fix 3
This commit is contained in:
@@ -14,6 +14,7 @@ interface AuthContextType {
|
||||
refreshUser: () => Promise<void>;
|
||||
}
|
||||
|
||||
// THIS LINE IS CRUCIAL AND MUST BE PRESENT AND UNCOMMENTED
|
||||
const AuthContext = createContext<AuthContextType | null>(null);
|
||||
|
||||
export const useAuth = () => {
|
||||
@@ -33,7 +34,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
const initAuth = async () => {
|
||||
try {
|
||||
await tokenManager.initialize();
|
||||
|
||||
|
||||
if (authService.isAuthenticated()) {
|
||||
const profile = await authService.getCurrentUser();
|
||||
setUser(profile);
|
||||
@@ -66,7 +67,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
const updateProfile = useCallback(async (updates: Partial<UserProfile>) => {
|
||||
const updated = await authService.updateProfile(updates);
|
||||
setUser(updated);
|
||||
}, [updateProfile]);
|
||||
}, []);
|
||||
|
||||
const refreshUser = useCallback(async () => {
|
||||
if (authService.isAuthenticated()) {
|
||||
@@ -79,10 +80,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
useEffect(() => {
|
||||
if (!user) return;
|
||||
|
||||
// Check token expiry every minute
|
||||
const interval = setInterval(async () => {
|
||||
try {
|
||||
await tokenManager.getAccessToken(); // This will refresh if needed
|
||||
await tokenManager.getAccessToken();
|
||||
} catch (error) {
|
||||
console.error('Token refresh failed:', error);
|
||||
await logout();
|
||||
@@ -93,7 +93,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
}, [user, logout]);
|
||||
|
||||
return (
|
||||
<AuthContext.Provider
|
||||
<AuthContext.Provider // This is now defined!
|
||||
value={{
|
||||
user,
|
||||
isAuthenticated: !!user,
|
||||
|
||||
Reference in New Issue
Block a user