diff --git a/src/http.ts b/src/http.ts index 842c92c..91ca579 100644 --- a/src/http.ts +++ b/src/http.ts @@ -31,7 +31,8 @@ axios.interceptors.response.use( }, (error) => { if (error.response && error.response.status === 401) { - navigate('/login') + navigate('/login'); + store.dispatch(setToken('')); } return Promise.reject(error); diff --git a/src/layout/AuthLayout.tsx b/src/layout/AuthLayout.tsx index 8511231..8a720b7 100644 --- a/src/layout/AuthLayout.tsx +++ b/src/layout/AuthLayout.tsx @@ -9,7 +9,7 @@ const AuthLayout = () => { - ) -} + ); +}; -export default AuthLayout \ No newline at end of file +export default AuthLayout; \ No newline at end of file diff --git a/src/pages/profile/index.tsx b/src/pages/profile/index.tsx index e8a87df..98fae12 100644 --- a/src/pages/profile/index.tsx +++ b/src/pages/profile/index.tsx @@ -70,10 +70,11 @@ const Profile = () => { const {data,isLoading,isFetching,error} = useQuery({ queryKey:["profile",mutation], - queryFn:()=>{ + queryFn: () => { return axios.get('/profile'); } - }) + }); + return ( <> {!mutation.isPending && ( diff --git a/src/pages/profile/section/components/ModalConfigDetails.tsx b/src/pages/profile/section/components/ModalConfigDetails.tsx index 77c1521..e073a1a 100644 --- a/src/pages/profile/section/components/ModalConfigDetails.tsx +++ b/src/pages/profile/section/components/ModalConfigDetails.tsx @@ -28,10 +28,11 @@ const ModalConfigDetails = ({ maxTraffic: number | "unlimited"; traffic: number; }) => { - const navigate = useNavigate() + const navigate = useNavigate(); const copyToClipboard = async (textToCopy: string) => { try { await navigator.clipboard.writeText(textToCopy); + toast.success("متن با موفقیت کپی شد!"); } catch (err) { toast.error(`Failed to copy: , ${err}`); diff --git a/src/pages/tutorial/section/Tutorials.tsx b/src/pages/tutorial/section/Tutorials.tsx index f7efbbe..6c24968 100644 --- a/src/pages/tutorial/section/Tutorials.tsx +++ b/src/pages/tutorial/section/Tutorials.tsx @@ -5,13 +5,13 @@ import useAxios from "../../../hooks/useAxios"; import { useQuery } from "@tanstack/react-query"; const Tutorials = () => { - const axios = useAxios() + const axios = useAxios(); const {data,error,isLoading,isFetching} = useQuery({ queryKey:["categoryLearning"], - queryFn:()=>{ - return axios.get('/home/category/learning') + queryFn: () => { + return axios.get('/home/category/learning'); } - }) + }); const [activeTutorial, setActiveTutorial] = useState(1); return (
diff --git a/src/utils/auth.ts b/src/utils/auth.ts index df34fa4..0ca9012 100644 --- a/src/utils/auth.ts +++ b/src/utils/auth.ts @@ -8,11 +8,13 @@ const isTokenValid = (token: string): boolean => { return !!token; } catch (error) { console.error("Token validation error:", error); + return false; } }; export const isAuthenticated = () : boolean => { - const {token} = useSelector((state : RootState) => state.token) + const {token} = useSelector((state : RootState) => state.token); + return isTokenValid(token); }; diff --git a/vite.config.ts b/vite.config.ts index 5a33944..7ea1e81 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,4 +4,4 @@ import react from '@vitejs/plugin-react' // https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], -}) +});