Add new frontend - fix 3
This commit is contained in:
6426
frontend/package-lock.json
generated
Normal file
6426
frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,7 @@ interface AuthContextType {
|
|||||||
refreshUser: () => Promise<void>;
|
refreshUser: () => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// THIS LINE IS CRUCIAL AND MUST BE PRESENT AND UNCOMMENTED
|
||||||
const AuthContext = createContext<AuthContextType | null>(null);
|
const AuthContext = createContext<AuthContextType | null>(null);
|
||||||
|
|
||||||
export const useAuth = () => {
|
export const useAuth = () => {
|
||||||
@@ -66,7 +67,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||||||
const updateProfile = useCallback(async (updates: Partial<UserProfile>) => {
|
const updateProfile = useCallback(async (updates: Partial<UserProfile>) => {
|
||||||
const updated = await authService.updateProfile(updates);
|
const updated = await authService.updateProfile(updates);
|
||||||
setUser(updated);
|
setUser(updated);
|
||||||
}, [updateProfile]);
|
}, []);
|
||||||
|
|
||||||
const refreshUser = useCallback(async () => {
|
const refreshUser = useCallback(async () => {
|
||||||
if (authService.isAuthenticated()) {
|
if (authService.isAuthenticated()) {
|
||||||
@@ -79,10 +80,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!user) return;
|
if (!user) return;
|
||||||
|
|
||||||
// Check token expiry every minute
|
|
||||||
const interval = setInterval(async () => {
|
const interval = setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
await tokenManager.getAccessToken(); // This will refresh if needed
|
await tokenManager.getAccessToken();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Token refresh failed:', error);
|
console.error('Token refresh failed:', error);
|
||||||
await logout();
|
await logout();
|
||||||
@@ -93,7 +93,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||||||
}, [user, logout]);
|
}, [user, logout]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuthContext.Provider
|
<AuthContext.Provider // This is now defined!
|
||||||
value={{
|
value={{
|
||||||
user,
|
user,
|
||||||
isAuthenticated: !!user,
|
isAuthenticated: !!user,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AuthProvider } from '../api';
|
import { AuthProvider } from '../contexts/AuthContext';
|
||||||
import '../styles/globals.css';
|
import '../styles/globals.css';
|
||||||
|
|
||||||
function App({ Component, pageProps }: any) {
|
function App({ Component, pageProps }: any) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
CloudArrowUpIcon,
|
CloudArrowUpIcon,
|
||||||
BuildingStorefrontIcon,
|
BuildingStorefrontIcon,
|
||||||
UserCircleIcon,
|
UserCircleIcon,
|
||||||
|
CpuChipIcon
|
||||||
} from '@heroicons/react/24/outline';
|
} from '@heroicons/react/24/outline';
|
||||||
import { SalesUploader } from '../components/data/SalesUploader';
|
import { SalesUploader } from '../components/data/SalesUploader';
|
||||||
import { TrainingProgressCard } from '../components/training/TrainingProgressCard';
|
import { TrainingProgressCard } from '../components/training/TrainingProgressCard';
|
||||||
|
|||||||
Reference in New Issue
Block a user