-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(refactor) start integrating React Router for auth redirects, etc
- Loading branch information
Zach Lysobey
committed
Jul 7, 2019
1 parent
d25705a
commit 50d2c86
Showing
5 changed files
with
184 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react' | ||
import { UserSession } from 'blockstack' | ||
import { Route, Redirect, RouteProps, RouteComponentProps } from 'react-router-dom' | ||
|
||
const LandingRedirect: React.StatelessComponent<Partial<RouteProps>> = ({ | ||
location | ||
}) => | ||
<Redirect | ||
to={{ | ||
pathname: "/landing/", | ||
state: { from: location } | ||
}} | ||
/> | ||
|
||
interface Props extends RouteProps { | ||
userSession: UserSession, | ||
component: React.ComponentType<RouteComponentProps<any>> | React.ComponentType<any>, | ||
} | ||
export const PrivateRoute: React.StatelessComponent<Props> = ({ | ||
component: Component, | ||
userSession, | ||
...rest | ||
}) => { | ||
const isSignedIn = userSession.isUserSignedIn() | ||
return ( | ||
<Route {...rest} | ||
render={props => isSignedIn | ||
? <Component {...props} /> | ||
: <LandingRedirect {...props} /> | ||
} | ||
/> | ||
) | ||
} |
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