restrictions in the accessibility of URLs
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import { Route, Redirect } from 'react-router-dom';
|
||||
|
||||
|
||||
class IsLoggedRoute extends Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Route
|
||||
{...this.props.exact}
|
||||
render={({ location }) =>
|
||||
!this.props.isAuthenticated ? (
|
||||
this.props.children
|
||||
) : (
|
||||
<Redirect
|
||||
to={{
|
||||
pathname: "/",
|
||||
state: { from: location }
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
IsLoggedRoute.propTypes = {
|
||||
isAuthenticated: PropTypes.bool.isRequired
|
||||
};
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
isAuthenticated: state.auth.isAuthenticated,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps, null)(IsLoggedRoute);
|
||||
@@ -31,7 +31,7 @@ class PrivateRoute extends Component {
|
||||
}
|
||||
|
||||
PrivateRoute.propTypes = {
|
||||
isAuthenticated: PropTypes.bool
|
||||
isAuthenticated: PropTypes.bool.isRequired
|
||||
};
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import { Route, Redirect, withRouter } from 'react-router-dom';
|
||||
|
||||
|
||||
class PrivateRoute extends Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Route
|
||||
{...this.props.exact}
|
||||
render={({ location }) =>
|
||||
this.props.isAuthenticated &&
|
||||
this.props.user &&
|
||||
this.props.user.blocklyRole !== 'user' ? (
|
||||
this.props.children
|
||||
) : (()=>{
|
||||
return (
|
||||
<Redirect
|
||||
to={{
|
||||
pathname: "/",
|
||||
state: { from: location }
|
||||
}}
|
||||
/>
|
||||
)
|
||||
})()
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
PrivateRoute.propTypes = {
|
||||
isAuthenticated: PropTypes.bool.isRequired,
|
||||
user: PropTypes.object
|
||||
};
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
isAuthenticated: state.auth.isAuthenticated,
|
||||
userRole: state.auth.user
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps, null)(withRouter(PrivateRoute));
|
||||
@@ -6,6 +6,9 @@ import { visitPage } from '../../actions/generalActions';
|
||||
import { Route, Switch, withRouter } from 'react-router-dom';
|
||||
|
||||
import PrivateRoute from './PrivateRoute';
|
||||
import PrivateRouteCreator from './PrivateRouteCreator';
|
||||
import IsLoggedRoute from './IsLoggedRoute';
|
||||
|
||||
import Home from '../Home';
|
||||
import Tutorial from '../Tutorial/Tutorial';
|
||||
import TutorialHome from '../Tutorial/TutorialHome';
|
||||
@@ -32,9 +35,9 @@ class Routes extends Component {
|
||||
<Route path="/" exact component={Home} />
|
||||
// Tutorials
|
||||
<Route path="/tutorial" exact component={TutorialHome} />
|
||||
<PrivateRoute path="/tutorial/builder" exact>
|
||||
<PrivateRouteCreator path="/tutorial/builder" exact>
|
||||
<Builder/>
|
||||
</PrivateRoute>
|
||||
</PrivateRouteCreator>
|
||||
<Route path="/tutorial/:tutorialId" exact component={Tutorial} />
|
||||
// Sharing
|
||||
<Route path="/share/:shareId" exact component={Project} />
|
||||
@@ -49,7 +52,9 @@ class Routes extends Component {
|
||||
<Project/>
|
||||
</PrivateRoute>
|
||||
// User
|
||||
<Route path="/user/login" exact component={Login} />
|
||||
<IsLoggedRoute path="/user/login" exact>
|
||||
<Login />
|
||||
</IsLoggedRoute>
|
||||
// settings
|
||||
<Route path="/settings" exact component={Settings} />
|
||||
// privacy
|
||||
|
||||
Reference in New Issue
Block a user