-
-
Save LukeSmetham/15024b3700dca90d2b2a4ace44d099e4 to your computer and use it in GitHub Desktop.
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
import React from 'react'; | |
import { connect } from 'react-redux'; | |
import { Redirect, Route } from 'react-router-dom'; | |
// Screens // | |
import LoadingScreen from 'screens/LoadingScreen'; | |
// Redux // | |
import { createStructuredSelector } from 'reselect'; | |
import { makeSelectIsAuthed } from 'data/auth/selectors'; | |
const AuthedRoute = ({ component: Component, isAuthed, loading, queueSnackbar, ...rest }) => { | |
return ( | |
<Route | |
{...rest} | |
render={(props) => { | |
if (loading) { | |
return <LoadingScreen />; | |
} | |
if (!isAuthed) { | |
return ( | |
<Redirect | |
to={{ | |
pathname: '/', | |
state: { conferenceAlias: props.match.params.conferenceAlias }, | |
}} | |
/> | |
); | |
} | |
return <Component {...props} />; | |
}} | |
/> | |
); | |
}; | |
const mapStateToProps = createStructuredSelector({ | |
isAuthed: makeSelectIsAuthed(), | |
}); | |
export default connect(mapStateToProps)(AuthedRoute); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment