adding in some files for the authentication flow and cleaning things u
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
|
||||
import Home from "./pages/Home";
|
||||
import Login from "./pages/Login";
|
||||
import ProtectedRoute from "./components/ProtectedRoute";
|
||||
import testConnection from "@nirvana/core";
|
||||
|
||||
testConnection();
|
||||
@@ -25,8 +26,15 @@ function App() {
|
||||
<HashRouter>
|
||||
<div className="App">
|
||||
<Routes>
|
||||
<Route path="/" element={<Login />} />
|
||||
<Route path="/home" element={<Home />} />
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route
|
||||
path="/home"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<Home />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
{/* <Route exact path="/profile/create" component={Sit} />
|
||||
<Route exact path="/profile/edit" component={Sit} /> */}
|
||||
</Routes>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Route, useNavigate } from "react-router-dom";
|
||||
|
||||
import { useGetUserDetails } from "../../controller/index";
|
||||
|
||||
export default function ProtectedRoute({ ...children }) {
|
||||
const { isLoading, isError } = useGetUserDetails();
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
if (isLoading) return <span>please wait while we authenticate you</span>;
|
||||
|
||||
if (isError) {
|
||||
// toast.error("Please sign in first!");
|
||||
navigate("/login");
|
||||
|
||||
return <span>you are not allowed here!</span>;
|
||||
}
|
||||
|
||||
// if we can successfully get user details, we are good to continue
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
Reference in New Issue
Block a user