-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(FE) Add Retrieving a User Information (#70)
* Add react query * Add axios deps * Save user data in store * Add protected routes * Add workspace page * Add lastWorksapceId to user controller * Change routes paths * Add workspace page * Add retrieving a user information
- Loading branch information
Showing
20 changed files
with
490 additions
and
40 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
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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 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 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,30 @@ | ||
import { ReactNode, useContext } from "react"; | ||
import { useLocation, Navigate } from "react-router-dom"; | ||
import { AuthContext } from "../../contexts/AuthContext"; | ||
import { useSelector } from "react-redux"; | ||
import { selectUser } from "../../store/userSlice"; | ||
|
||
interface RejectLoggedInRouteProps { | ||
children?: ReactNode; | ||
} | ||
|
||
const GuestRoute = (props: RejectLoggedInRouteProps) => { | ||
const { children } = props; | ||
const { isLoggedIn } = useContext(AuthContext); | ||
const location = useLocation(); | ||
const userStore = useSelector(selectUser); | ||
|
||
if (isLoggedIn) { | ||
return ( | ||
<Navigate | ||
to={`/workspace/${userStore.data?.lastWorkspaceId}`} | ||
state={{ from: location }} | ||
replace | ||
/> | ||
); | ||
} | ||
|
||
return children; | ||
}; | ||
|
||
export default GuestRoute; |
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,30 @@ | ||
import { ReactNode, useContext } from "react"; | ||
import { useLocation, Navigate } from "react-router-dom"; | ||
import { AuthContext } from "../../contexts/AuthContext"; | ||
import { Backdrop, CircularProgress } from "@mui/material"; | ||
|
||
interface PrivateRouteProps { | ||
children?: ReactNode; | ||
} | ||
|
||
const PrivateRoute = (props: PrivateRouteProps) => { | ||
const { children } = props; | ||
const { isLoggedIn, isLoading } = useContext(AuthContext); | ||
const location = useLocation(); | ||
|
||
if (isLoading) { | ||
return ( | ||
<Backdrop open> | ||
<CircularProgress color="inherit" /> | ||
</Backdrop> | ||
); | ||
} | ||
|
||
if (!isLoggedIn) { | ||
return <Navigate to="/" state={{ from: location }} replace />; | ||
} | ||
|
||
return children; | ||
}; | ||
|
||
export default PrivateRoute; |
Oops, something went wrong.