ProtectedRoute Update

This commit is contained in:
=bhagwanSingh 2025-10-08 15:56:06 +05:30
parent c94ebd72a2
commit b3beb64265
2 changed files with 11 additions and 7 deletions

View File

@ -1,14 +1,18 @@
import { JSX, useLayoutEffect } from 'react'; import { JSX, useLayoutEffect } from 'react';
import { useDispatch } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { fetchUserDetails } from '../../store/slices/userSlice'; import { fetchUserDetails } from '../../store/slices/userSlice';
import { AppDispatch } from '../../store/store'; import { AppDispatch, RootState } from '../../store/store';
const ProtectedRoute = ({ children }: { children: JSX.Element }) => { const ProtectedRoute = ({ children }: { children: JSX.Element }) => {
const dispatch = useDispatch<AppDispatch>(); const dispatch = useDispatch<AppDispatch>();
const user = useSelector((state: RootState) => state.user);
// useLayoutEffect(() => { useLayoutEffect(() => {
dispatch(fetchUserDetails()); // Fetch only if we don't have user data yet
// }, []); if (user.id === null && user.loading === false) {
dispatch(fetchUserDetails());
}
}, [dispatch, user, status]);
return children; return children;
}; };

View File

@ -32,7 +32,7 @@ const initialState: UserState = {
language: "", language: "",
account: null, account: null,
picture: undefined, picture: undefined,
loading: true, loading: false,
error: null, error: null,
authorized: false, authorized: false,
accessToken: undefined, accessToken: undefined,