Created
October 21, 2016 15:36
-
-
Save bnhansn/add8b2c885c4c5f96e89cd6e250d8218 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // @flow | |
| import React from 'react'; | |
| import { Match, Redirect } from 'react-router'; | |
| type Props = { | |
| component: any, | |
| pattern: string, | |
| exactly?: boolean, | |
| isAuthenticated: boolean, | |
| willAuthenticate: boolean, | |
| } | |
| const MatchAuthenticated = ({ | |
| pattern, | |
| exactly, | |
| isAuthenticated, | |
| willAuthenticate, | |
| component: Component, | |
| }: Props) => | |
| <Match | |
| exactly={exactly} | |
| pattern={pattern} | |
| render={(props) => { | |
| if (isAuthenticated) { return <Component {...props} />; } | |
| if (willAuthenticate) { return null; } | |
| if (!willAuthenticate && !isAuthenticated) { return <Redirect to={{ pathname: '/login' }} />; } | |
| return null; | |
| }} | |
| />; | |
| export default MatchAuthenticated; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment