Skip to content

Commit

Permalink
Redirect to login page if no access token
Browse files Browse the repository at this point in the history
  • Loading branch information
subratamondal1 committed Mar 13, 2024
1 parent f934417 commit bd40c20
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions frontend/react-app/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Header from "./components/Header";
import Main from "./components/DynamicList";
import SearchBar from "./components/SearchBar";
import useRedirectToLogin from "./components/RedirectToLogin";

function App() {
useRedirectToLogin();
return (
<div className="max-w-[800px] min-w-min bg-white mx-auto m-0">
<Header></Header>
Expand Down
15 changes: 15 additions & 0 deletions frontend/react-app/src/components/RedirectToLogin.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useEffect } from "react";
import { useNavigate } from "react-router-dom";

const useRedirectToLogin = () => {
const navigate = useNavigate();

useEffect(() => {
const appToken = localStorage.getItem("appToken");
if (!appToken) {
navigate("/login");
}
}, [navigate]);
};

export default useRedirectToLogin;

0 comments on commit bd40c20

Please sign in to comment.