This commit is contained in:
xuqssq
2024-12-28 15:39:48 +08:00
parent b3ac241354
commit 6e8334ecaf
18 changed files with 5017 additions and 420 deletions

View File

@@ -1,7 +1,7 @@
import React from 'react';
import { Navigate,useLocation } from 'react-router-dom';
import { useAuth } from '@/contexts/AuthContext';
import { Spin } from 'antd';
import React from "react";
import { Navigate, useLocation } from "react-router-dom";
import { useAuth } from "@/contexts/AuthContext";
import { Spin } from "antd";
export const ProtectedRoute = ({ children }) => {
const { user, loading } = useAuth();
@@ -14,9 +14,11 @@ export const ProtectedRoute = ({ children }) => {
);
}
if (!user) {
return <Navigate to={`/login`} replace />;
if (!user?.id) {
return (
<Navigate to={`/login?redirectTo=${location.pathname || ""}`} replace />
);
}
return children;
};
};