From 781ca82f19ab15db29b0c176f60c74f406c491da Mon Sep 17 00:00:00 2001 From: Mubashir Shariq Date: Mon, 5 Feb 2024 13:10:29 +0530 Subject: [PATCH 1/2] removed redundant between client and server --- .../components/createRedirectWithUsername.jsx | 29 --------------- client/routes.jsx | 35 +++++-------------- client/utils/auth.js | 30 ---------------- server/routes/server.routes.js | 22 +++++++----- 4 files changed, 22 insertions(+), 94 deletions(-) delete mode 100644 client/components/createRedirectWithUsername.jsx delete mode 100644 client/utils/auth.js diff --git a/client/components/createRedirectWithUsername.jsx b/client/components/createRedirectWithUsername.jsx deleted file mode 100644 index a6b69233c4..0000000000 --- a/client/components/createRedirectWithUsername.jsx +++ /dev/null @@ -1,29 +0,0 @@ -import React from 'react'; -import { connect } from 'react-redux'; -import browserHistory from '../browserHistory'; - -const RedirectToUser = ({ username, url = '/:username/sketches' }) => { - React.useEffect(() => { - if (username == null) { - return; - } - - browserHistory.replace(url.replace(':username', username)); - }, [username]); - - return null; -}; - -function mapStateToProps(state) { - return { - username: state.user ? state.user.username : null - }; -} - -const ConnectedRedirectToUser = connect(mapStateToProps)(RedirectToUser); - -const createRedirectWithUsername = (url) => (props) => ( - -); - -export default createRedirectWithUsername; diff --git a/client/routes.jsx b/client/routes.jsx index 418a5bf99d..75d5c0e13f 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 createRedirectWithUsername 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 eda9464eba..1709f1246c 100644 --- a/server/routes/server.routes.js +++ b/server/routes/server.routes.js @@ -71,11 +71,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) => { @@ -84,18 +90,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', (req, res) => { From 7e17dab0cd84e72a8e9240c802a7419f4c91f2e5 Mon Sep 17 00:00:00 2001 From: Mubashir Shariq Date: Fri, 14 Jun 2024 19:07:26 +0530 Subject: [PATCH 2/2] 'c' --- client/modules/User/components/LoginForm.jsx | 2 +- client/modules/User/components/SignupForm.jsx | 2 +- client/routes.jsx | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/client/modules/User/components/LoginForm.jsx b/client/modules/User/components/LoginForm.jsx index bf851a5234..8efcfa22c7 100644 --- a/client/modules/User/components/LoginForm.jsx +++ b/client/modules/User/components/LoginForm.jsx @@ -2,7 +2,7 @@ import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Form, Field } from 'react-final-form'; import { useDispatch } from 'react-redux'; -import { AiOutlineEye, AiOutlineEyeInvisible } from 'react-icons/ai.js'; +import { AiOutlineEye, AiOutlineEyeInvisible } from 'react-icons/ai'; import Button from '../../../common/Button'; import { validateLogin } from '../../../utils/reduxFormUtils'; import { validateAndLoginUser } from '../actions'; diff --git a/client/modules/User/components/SignupForm.jsx b/client/modules/User/components/SignupForm.jsx index fae92ed066..6e967c5c4a 100644 --- a/client/modules/User/components/SignupForm.jsx +++ b/client/modules/User/components/SignupForm.jsx @@ -2,7 +2,7 @@ import { React, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Form, Field } from 'react-final-form'; import { useDispatch } from 'react-redux'; -import { AiOutlineEye, AiOutlineEyeInvisible } from 'react-icons/ai.js'; +import { AiOutlineEye, AiOutlineEyeInvisible } from 'react-icons/ai'; import { validateSignup } from '../../../utils/reduxFormUtils'; import { validateAndSignUpUser } from '../actions'; import Button from '../../../common/Button'; diff --git a/client/routes.jsx b/client/routes.jsx index 75d5c0e13f..5fc883b305 100644 --- a/client/routes.jsx +++ b/client/routes.jsx @@ -68,7 +68,6 @@ const routes = ( path="/:username/collections/:collection_id" component={CollectionView} /> -