From a35176afd7873a317af8b4d3844037ea0233776f Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Wed, 21 Dec 2022 19:45:57 +0530 Subject: made app unaccessible when not logged in --- src/App.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/App.js b/src/App.js index 8dfbf81..197b6f2 100644 --- a/src/App.js +++ b/src/App.js @@ -15,9 +15,11 @@ * along with this program. If not, see . */ -import { BrowserRouter, Route, Routes } from "react-router-dom"; +import { Route, Routes, useLocation } from "react-router-dom"; +import { useEffect } from "react"; import { ReactNotifications } from "react-notifications-component"; -import "./notifications_styles/notification.scss" +import axios from "axios"; +import "./notifications_styles/notification.scss"; import Navbar from './components/navbar/navbar'; import HomePage from './views/homepage'; @@ -32,8 +34,17 @@ import ManageInvoicesPage from './views/manage/invoices'; import './App.scss'; const App = () => { + // when location changes, ping server to check if logged in + // and don't ping if location is /login or /register + const location = useLocation(); + useEffect(_ => { + if (!["/login", "/register"].includes(location.pathname)) { + axios.post("/ping") + } + }, [location]); + return ( - + <>
@@ -50,7 +61,7 @@ const App = () => { 404}/>
-
+ ); } -- cgit v1.2.3