Refactor: Remove admin page button and protect /admin route when autologin occurs
This commit is contained in:
parent
6671a6c369
commit
30b3b4b0d6
2 changed files with 3 additions and 3 deletions
|
|
@ -3,7 +3,7 @@ import { Navigate } from "react-router-dom";
|
|||
import { AuthContext } from "../../contexts/authContext";
|
||||
|
||||
export const ProtectedAdminRoute = ({ children }) => {
|
||||
const { isAdmin, isAuthenticated, logout, getAuthentication, userData } =
|
||||
const { isAdmin, isAuthenticated, logout, getAuthentication, userData, autoLogin } =
|
||||
useContext(AuthContext);
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated && !getAuthentication()) {
|
||||
|
|
@ -16,7 +16,7 @@ export const ProtectedAdminRoute = ({ children }) => {
|
|||
return <Navigate to="/login" replace />;
|
||||
}
|
||||
|
||||
if (userData && !isAdmin) {
|
||||
if (userData && !isAdmin || autoLogin) {
|
||||
return <Navigate to="/" replace />;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ export default function Header() {
|
|||
</Button>
|
||||
)}
|
||||
|
||||
{isAdmin && (
|
||||
{isAdmin && !autoLogin && (
|
||||
<Button variant="outline" onClick={() => navigate("/admin")}>
|
||||
Admin page
|
||||
</Button>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue