Skip to content

Instantly share code, notes, and snippets.

@LukeSmetham
Created September 23, 2019 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save LukeSmetham/15024b3700dca90d2b2a4ace44d099e4 to your computer and use it in GitHub Desktop.
Save LukeSmetham/15024b3700dca90d2b2a4ace44d099e4 to your computer and use it in GitHub Desktop.
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