mirror of
https://github.com/20kaushik02/spotify-manager-web.git
synced 2026-01-25 16:14:06 +00:00
back. WiP
graph package (reactflow), updates. assets, some of the SEO. started with some basic components, login, navbar, etc.
This commit is contained in:
36
src/routes/AllRoutes.jsx
Normal file
36
src/routes/AllRoutes.jsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Route, Routes } from "react-router-dom";
|
||||
|
||||
import AuthOnlyRoutes from "./AuthOnlyRoutes";
|
||||
import UnAuthOnlyRoutes from "./UnAuthOnlyRoutes";
|
||||
|
||||
import Landing from "../pages/Landing";
|
||||
import PageNotFound from "../pages/PageNotFound";
|
||||
import Graph from "../pages/Graph";
|
||||
import Login from "../pages/Login";
|
||||
|
||||
const AllRoutes = () => {
|
||||
return (
|
||||
<Routes>
|
||||
{/* Routes that require user to be logged in */}
|
||||
<Route element={<AuthOnlyRoutes />}>
|
||||
<Route path="/graph" element={<Graph />} />
|
||||
{/* <Route path="/playlists" element={<Playlists />} /> */}
|
||||
</Route>
|
||||
|
||||
{/* Routes that require user to be logged *out* */}
|
||||
<Route element={<UnAuthOnlyRoutes />}>
|
||||
<Route path="/login" element={<Login />} />
|
||||
</Route>
|
||||
|
||||
{/* Common routes */}
|
||||
<Route path="/" element={<Landing />} />
|
||||
|
||||
<Route path="/graph2" element={<Graph />} />
|
||||
{/* 404 */}
|
||||
<Route path="/page-not-found" element={<PageNotFound />} />
|
||||
<Route path="*" element={<PageNotFound />} />
|
||||
</Routes>
|
||||
);
|
||||
};
|
||||
|
||||
export default AllRoutes;
|
||||
23
src/routes/AuthOnlyRoutes.jsx
Normal file
23
src/routes/AuthOnlyRoutes.jsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import React, { useContext } from "react";
|
||||
import { Navigate, Outlet, useLocation } from "react-router-dom";
|
||||
|
||||
import { AuthContext } from "../App";
|
||||
import { showWarnToastNotification } from "../components/ToastNotification";
|
||||
|
||||
function AuthOnlyRoutes() {
|
||||
let location = useLocation();
|
||||
const auth = useContext(AuthContext);
|
||||
|
||||
const handleRouteRender = () => {
|
||||
if (auth !== true) {
|
||||
showWarnToastNotification(<p>Sign in, please!</p>);
|
||||
return <Navigate to={"/login"} state={{ from: location }} />;
|
||||
} else {
|
||||
return <Outlet />;
|
||||
}
|
||||
};
|
||||
|
||||
return handleRouteRender();
|
||||
}
|
||||
|
||||
export default AuthOnlyRoutes;
|
||||
23
src/routes/UnAuthOnlyRoutes.jsx
Normal file
23
src/routes/UnAuthOnlyRoutes.jsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import React, { useContext } from "react";
|
||||
import { Navigate, Outlet, useLocation } from "react-router-dom";
|
||||
|
||||
import { AuthContext } from "../App";
|
||||
import { showWarnToastNotification } from "../components/ToastNotification";
|
||||
|
||||
function UnAuthOnlyRoutes() {
|
||||
let location = useLocation();
|
||||
const auth = useContext(AuthContext);
|
||||
|
||||
const handleRouteRender = () => {
|
||||
if (auth !== true) {
|
||||
return <Outlet />;
|
||||
} else {
|
||||
showWarnToastNotification(<p>Already logged in!</p>);
|
||||
return <Navigate to={"/graph"} state={{ from: location }} />;
|
||||
}
|
||||
};
|
||||
|
||||
return handleRouteRender();
|
||||
}
|
||||
|
||||
export default UnAuthOnlyRoutes;
|
||||
Reference in New Issue
Block a user