diff --git a/client/components/createRedirectWithUsername.jsx b/client/components/createRedirectWithUsername.jsx deleted file mode 100644 index a1d782e15f..0000000000 --- a/client/components/createRedirectWithUsername.jsx +++ /dev/null @@ -1,24 +0,0 @@ -import { useEffect } from 'react'; -import { useSelector } from 'react-redux'; -import { useHistory } from 'react-router-dom'; -import PropTypes from 'prop-types'; - -const RedirectToUser = ({ url = '/:username/sketches' }) => { - const history = useHistory(); - const username = useSelector((state) => - state.user ? state.user.username : null - ); - useEffect(() => { - if (username) { - history.replace(url.replace(':username', username)); - } - }, [history, url, username]); - - return null; -}; - -RedirectToUser.propTypes = { - url: PropTypes.string.isRequired -}; - -export default RedirectToUser; diff --git a/client/routes.jsx b/client/routes.jsx index c0e189441d..5fc883b305 100644 --- a/client/routes.jsx +++ b/client/routes.jsx @@ -17,13 +17,7 @@ import NewPasswordView from './modules/User/pages/NewPasswordView'; import AccountView from './modules/User/pages/AccountView'; import CollectionView from './modules/User/pages/CollectionView'; import DashboardView from './modules/User/pages/DashboardView'; -import RedirectToUser from './components/createRedirectWithUsername'; import { getUser } from './modules/User/actions'; -import { - userIsAuthenticated, - userIsNotAuthenticated, - userIsAuthorized -} from './utils/auth'; /** * `params` is no longer a top-level route component prop in v4. @@ -51,25 +45,19 @@ Route.propTypes = { const routes = ( - - + + - + - + - - } - /> - } - /> - + + + - diff --git a/client/utils/auth.js b/client/utils/auth.js deleted file mode 100644 index 6f2fb4e21d..0000000000 --- a/client/utils/auth.js +++ /dev/null @@ -1,30 +0,0 @@ -import { connectedRouterRedirect } from 'redux-auth-wrapper/history4/redirect'; -import locationHelperBuilder from 'redux-auth-wrapper/history4/locationHelper'; - -const locationHelper = locationHelperBuilder({}); - -export const userIsAuthenticated = connectedRouterRedirect({ - // The url to redirect user to if they fail - redirectPath: '/login', - // Determine if the user is authenticated or not - authenticatedSelector: (state) => state.user.authenticated === true, - // A nice display name for this check - wrapperDisplayName: 'UserIsAuthenticated' -}); - -export const userIsNotAuthenticated = connectedRouterRedirect({ - redirectPath: (state, ownProps) => - locationHelper.getRedirectQueryParam(ownProps) || '/', - allowRedirectBack: false, - authenticatedSelector: (state) => state.user.authenticated === false, - wrapperDisplayName: 'UserIsNotAuthenticated' -}); - -export const userIsAuthorized = connectedRouterRedirect({ - redirectPath: '/', - allowRedirectBack: false, - authenticatedSelector: (state, ownProps) => { - const { username } = ownProps.params; - return state.user.username === username; - } -}); diff --git a/server/routes/server.routes.js b/server/routes/server.routes.js index eed2ea87da..68ffffccbd 100644 --- a/server/routes/server.routes.js +++ b/server/routes/server.routes.js @@ -76,11 +76,17 @@ router.get('/login', (req, res) => { }); router.get('/reset-password', (req, res) => { - res.send(renderIndex()); + if (req.user) { + return res.redirect('/account'); + } + return res.send(renderIndex()); }); router.get('/reset-password/:reset_password_token', (req, res) => { - res.send(renderIndex()); + if (req.user) { + return res.redirect('/account'); + } + return res.send(renderIndex()); }); router.get('/verify', (req, res) => { @@ -89,18 +95,18 @@ router.get('/verify', (req, res) => { router.get('/sketches', (req, res) => { if (req.user) { - res.send(renderIndex()); - } else { - res.redirect('/login'); + const { username } = req.user; + return res.redirect(`/${username}/sketches`); } + return res.redirect('/login'); }); router.get('/assets', (req, res) => { if (req.user) { - res.send(renderIndex()); - } else { - res.redirect('/login'); + const { username } = req.user; + return res.redirect(`/${username}/assets`); } + return res.redirect('/login'); }); router.get('/:username/assets', async (req, res) => {