generated from TetiZ/vite-react-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from AnWhiteM/new-auth
commit
- Loading branch information
Showing
21 changed files
with
270 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,68 @@ | ||
import { HomePage } from "../HomePage/HomePage"; | ||
import { LoginPage } from "../LoginPage/LoginPage"; | ||
import { Route, Routes } from 'react-router-dom'; | ||
import Login from "../Login/Login"; | ||
import Register from "../Register/Register"; | ||
import { lazy, Suspense, useEffect } from "react"; | ||
|
||
// import { HomePage } from "../HomePage/HomePage"; | ||
// import { LoginPage } from "../LoginPage/LoginPage"; | ||
// import Login from "../Login/Login"; | ||
// import Register from "../Register/Register"; | ||
|
||
import { Route, Routes } from "react-router-dom"; | ||
import { Toaster } from "react-hot-toast"; | ||
|
||
import { useDispatch, useSelector } from "react-redux"; | ||
import { refreshUser } from "../../redux/auth/operations"; | ||
import { selectIsRefreshing } from "../../redux/auth/selectror"; | ||
|
||
import RestrictedRoute from "../RestrictedRoute/RestrictedRoute"; | ||
import PrivateRoute from "../PrivateRoute/PrivateRoute"; | ||
|
||
const HomePage = lazy(() => import("../../pages/HomePage/HomePage")); | ||
const LoginPage = lazy(() => import("../../pages/LoginPage/LoginPage")); | ||
const Login = lazy(() => import("../../pages/Login/Login")); | ||
const Register = lazy(() => import("../../pages/Register/Register")); | ||
const NotFoundPage = lazy(() => import("../../pages/NotFoundPage")); | ||
|
||
export const App = () => { | ||
|
||
return ( | ||
<> | ||
<Routes> | ||
<Route index element={<LoginPage />} /> | ||
<Route path="/welcome" element={<LoginPage />} /> | ||
<Route path="/auth/register" element={<Register />} /> | ||
<Route path="/auth/login" element={<Login />} /> | ||
<Route path="/home" element={<HomePage />} /> | ||
</Routes> | ||
|
||
</> | ||
) | ||
|
||
const isRefreshing = useSelector(selectIsRefreshing); | ||
const dispatch = useDispatch(); | ||
|
||
useEffect(() => { | ||
dispatch(refreshUser()); | ||
}, [dispatch]); | ||
return ( | ||
<> | ||
{isRefreshing ? ( | ||
<b>Loading...</b> | ||
) : ( | ||
<Suspense fallback={null}> | ||
<Routes> | ||
<Route index element={<LoginPage />} /> | ||
<Route path="/welcome" element={<LoginPage />} /> | ||
<Route | ||
path="/auth/register" | ||
element={ | ||
<RestrictedRoute component={<Register />} redirectTo="/home" /> | ||
} | ||
/> | ||
<Route | ||
path="/auth/login" | ||
element={ | ||
<RestrictedRoute component={<Login />} redirectTo="/home" /> | ||
} | ||
/> | ||
<Route | ||
path="/home" | ||
element={ | ||
<PrivateRoute | ||
component={<HomePage />} | ||
redirectTo="/auth/login" | ||
/> | ||
} | ||
/> | ||
<Route path="*" element={<NotFoundPage />} /> | ||
</Routes> | ||
<Toaster position="top-right" /> | ||
</Suspense> | ||
)} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// import css from "./AppBar.module.css"; | ||
|
||
export default function AppBar() { | ||
return <div className={css.container}></div>; | ||
return <div></div>; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useSelector } from "react-redux"; | ||
import { selectIsLoggedIn } from "../../redux/auth/selectror"; | ||
import { Navigate } from "react-router-dom"; | ||
|
||
export default function PrivateRoute({ | ||
component: Component, | ||
redirectTo = "/auth/login", | ||
}) { | ||
const isLoggedIn = useSelector(selectIsLoggedIn); | ||
|
||
return isLoggedIn ? Component : <Navigate to={redirectTo} />; | ||
} |
Oops, something went wrong.