-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app-auth): add PrivateRoute and initialization hook
- Loading branch information
1 parent
a615b3c
commit 6b864f3
Showing
5 changed files
with
47 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { reducer, actions, name } from "./slice"; | ||
import { reducer, actions, name, selectors } from "./slice"; | ||
import saga from "./saga"; | ||
|
||
export { reducer, actions, name, saga }; | ||
export { reducer, actions, name, saga, selectors }; |
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,24 @@ | ||
import { selectors as authSelectors } from '@pipeline/auth'; | ||
import React from 'react'; | ||
import { Route, Redirect } from 'react-router-dom'; | ||
import { useSelector } from 'react-redux'; | ||
import { RoutingPath } from '@pipeline/routing'; | ||
|
||
type Props = React.ComponentProps<typeof Route>; | ||
|
||
/** | ||
* A Route which is aware of the authentication status of the current user. | ||
* If the user is not authenticated, it redirects to the SignUp Route. | ||
* If the user is authenticated, it behaves like a standard Route component. | ||
*/ | ||
const PrivateRoute: React.FC<Props> = (props) => { | ||
|
||
const currentUser = useSelector(authSelectors.getCurrentUser); | ||
|
||
return currentUser ? <Route {...props}/> : <Redirect to={RoutingPath.Signup}/> | ||
} | ||
|
||
|
||
PrivateRoute.displayName = 'PrivateRoute'; | ||
|
||
export default PrivateRoute; |
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,4 @@ | ||
import { RoutingPath } from "./routingPath"; | ||
import PrivateRoute from "./PrivateRoute"; | ||
|
||
export { | ||
RoutingPath | ||
} | ||
export { RoutingPath, PrivateRoute }; |