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

View File

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