feat: add require no auth route
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
// import React from 'react'
|
||||||
|
import { Navigate } from "react-router-dom";
|
||||||
|
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
|
export default function RequireNoAuth({ children, redirectTo = "/" }) {
|
||||||
|
const { token } = useSelector((store) => store.authData);
|
||||||
|
return token ? <Navigate to={redirectTo} replace /> : children;
|
||||||
|
}
|
||||||
+11
-1
@@ -8,10 +8,12 @@ import HomePage from "./home";
|
|||||||
import ChatPage from "./chat";
|
import ChatPage from "./chat";
|
||||||
import ContactsPage from "./contacts";
|
import ContactsPage from "./contacts";
|
||||||
import RequireAuth from "../common/component/RequireAuth";
|
import RequireAuth from "../common/component/RequireAuth";
|
||||||
|
import RequireNoAuth from "../common/component/RequireNoAuth";
|
||||||
|
|
||||||
import store from "../app/store";
|
import store from "../app/store";
|
||||||
import InvitePage from "./invite";
|
import InvitePage from "./invite";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
import ResourceManagement from "./resources";
|
||||||
|
|
||||||
const PageRoutes = () => {
|
const PageRoutes = () => {
|
||||||
const { online } = useSelector((store) => store.ui);
|
const { online } = useSelector((store) => store.ui);
|
||||||
@@ -28,7 +30,14 @@ const PageRoutes = () => {
|
|||||||
return (
|
return (
|
||||||
<HashRouter>
|
<HashRouter>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/login" element={<LoginPage />} />
|
<Route
|
||||||
|
path="/login"
|
||||||
|
element={
|
||||||
|
<RequireNoAuth>
|
||||||
|
<LoginPage />
|
||||||
|
</RequireNoAuth>
|
||||||
|
}
|
||||||
|
/>
|
||||||
<Route path="/invite" element={<InvitePage />} />
|
<Route path="/invite" element={<InvitePage />} />
|
||||||
<Route
|
<Route
|
||||||
path="/"
|
path="/"
|
||||||
@@ -48,6 +57,7 @@ const PageRoutes = () => {
|
|||||||
<Route index element={<ContactsPage />} />
|
<Route index element={<ContactsPage />} />
|
||||||
<Route path=":user_id" element={<ContactsPage />} />
|
<Route path=":user_id" element={<ContactsPage />} />
|
||||||
</Route>
|
</Route>
|
||||||
|
<Route path="files" element={<ResourceManagement />}></Route>
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="*" element={<NotFoundPage />} />
|
<Route path="*" element={<NotFoundPage />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|||||||
Reference in New Issue
Block a user