Skip to content

Removed redundant redirects between client and server #2993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
24 changes: 0 additions & 24 deletions client/components/createRedirectWithUsername.jsx

This file was deleted.

34 changes: 7 additions & 27 deletions client/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -51,25 +45,19 @@ Route.propTypes = {
const routes = (
<Switch>
<Route exact path="/" component={IDEView} />
<Route path="/login" component={userIsNotAuthenticated(LoginView)} />
<Route path="/signup" component={userIsNotAuthenticated(SignupView)} />
<Route path="/login" component={LoginView} />
<Route path="/signup" component={SignupView} />
<Route
path="/reset-password/:reset_password_token"
component={NewPasswordView}
/>
<Route
path="/reset-password"
component={userIsNotAuthenticated(ResetPasswordView)}
/>
<Route path="/reset-password" component={ResetPasswordView} />
<Route path="/verify" component={EmailVerificationView} />
<Route path="/projects/:project_id" component={IDEView} />
<Route path="/:username/full/:project_id" component={FullView} />
<Route path="/full/:project_id" component={FullView} />

<Route
path="/:username/assets"
component={userIsAuthenticated(userIsAuthorized(DashboardView))}
/>
<Route path="/:username/assets" component={DashboardView} />
<Route
path="/:username/sketches/:project_id/add-to-collection"
component={IDEView}
Expand All @@ -81,18 +69,10 @@ const routes = (
component={CollectionView}
/>
<Route path="/:username/collections" component={DashboardView} />

<Route
path="/sketches"
component={() => <RedirectToUser url="/:username/sketches" />}
/>
<Route
path="/assets"
component={() => <RedirectToUser url="/:username/assets" />}
/>
<Route path="/account" component={userIsAuthenticated(AccountView)} />
<Route path="/sketches" />
<Route path="/assets" />
<Route path="/account" component={AccountView} />
<Route path="/about" component={IDEView} />

<Route path="/privacy-policy" component={PrivacyPolicy} />
<Route path="/terms-of-use" component={TermsOfUse} />
<Route path="/code-of-conduct" component={CodeOfConduct} />
Expand Down
30 changes: 0 additions & 30 deletions client/utils/auth.js

This file was deleted.

22 changes: 14 additions & 8 deletions server/routes/server.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand Down
Loading