Skip to content

Commit 982fcfc

Browse files
authored
Merge pull request #2993 from Mubashirshariq/Fix/Redundant_Redirects_between_server_and_client
Removed redundant redirects between client and server
2 parents 8386574 + 8347477 commit 982fcfc

File tree

4 files changed

+21
-89
lines changed

4 files changed

+21
-89
lines changed

client/components/createRedirectWithUsername.jsx

-24
This file was deleted.

client/routes.jsx

+7-27
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ import NewPasswordView from './modules/User/pages/NewPasswordView';
1717
import AccountView from './modules/User/pages/AccountView';
1818
import CollectionView from './modules/User/pages/CollectionView';
1919
import DashboardView from './modules/User/pages/DashboardView';
20-
import RedirectToUser from './components/createRedirectWithUsername';
2120
import { getUser } from './modules/User/actions';
22-
import {
23-
userIsAuthenticated,
24-
userIsNotAuthenticated,
25-
userIsAuthorized
26-
} from './utils/auth';
2721

2822
/**
2923
* `params` is no longer a top-level route component prop in v4.
@@ -51,25 +45,19 @@ Route.propTypes = {
5145
const routes = (
5246
<Switch>
5347
<Route exact path="/" component={IDEView} />
54-
<Route path="/login" component={userIsNotAuthenticated(LoginView)} />
55-
<Route path="/signup" component={userIsNotAuthenticated(SignupView)} />
48+
<Route path="/login" component={LoginView} />
49+
<Route path="/signup" component={SignupView} />
5650
<Route
5751
path="/reset-password/:reset_password_token"
5852
component={NewPasswordView}
5953
/>
60-
<Route
61-
path="/reset-password"
62-
component={userIsNotAuthenticated(ResetPasswordView)}
63-
/>
54+
<Route path="/reset-password" component={ResetPasswordView} />
6455
<Route path="/verify" component={EmailVerificationView} />
6556
<Route path="/projects/:project_id" component={IDEView} />
6657
<Route path="/:username/full/:project_id" component={FullView} />
6758
<Route path="/full/:project_id" component={FullView} />
6859

69-
<Route
70-
path="/:username/assets"
71-
component={userIsAuthenticated(userIsAuthorized(DashboardView))}
72-
/>
60+
<Route path="/:username/assets" component={DashboardView} />
7361
<Route
7462
path="/:username/sketches/:project_id/add-to-collection"
7563
component={IDEView}
@@ -81,18 +69,10 @@ const routes = (
8169
component={CollectionView}
8270
/>
8371
<Route path="/:username/collections" component={DashboardView} />
84-
85-
<Route
86-
path="/sketches"
87-
component={() => <RedirectToUser url="/:username/sketches" />}
88-
/>
89-
<Route
90-
path="/assets"
91-
component={() => <RedirectToUser url="/:username/assets" />}
92-
/>
93-
<Route path="/account" component={userIsAuthenticated(AccountView)} />
72+
<Route path="/sketches" />
73+
<Route path="/assets" />
74+
<Route path="/account" component={AccountView} />
9475
<Route path="/about" component={IDEView} />
95-
9676
<Route path="/privacy-policy" component={PrivacyPolicy} />
9777
<Route path="/terms-of-use" component={TermsOfUse} />
9878
<Route path="/code-of-conduct" component={CodeOfConduct} />

client/utils/auth.js

-30
This file was deleted.

server/routes/server.routes.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,17 @@ router.get('/login', (req, res) => {
7676
});
7777

7878
router.get('/reset-password', (req, res) => {
79-
res.send(renderIndex());
79+
if (req.user) {
80+
return res.redirect('/account');
81+
}
82+
return res.send(renderIndex());
8083
});
8184

8285
router.get('/reset-password/:reset_password_token', (req, res) => {
83-
res.send(renderIndex());
86+
if (req.user) {
87+
return res.redirect('/account');
88+
}
89+
return res.send(renderIndex());
8490
});
8591

8692
router.get('/verify', (req, res) => {
@@ -89,18 +95,18 @@ router.get('/verify', (req, res) => {
8995

9096
router.get('/sketches', (req, res) => {
9197
if (req.user) {
92-
res.send(renderIndex());
93-
} else {
94-
res.redirect('/login');
98+
const { username } = req.user;
99+
return res.redirect(`/${username}/sketches`);
95100
}
101+
return res.redirect('/login');
96102
});
97103

98104
router.get('/assets', (req, res) => {
99105
if (req.user) {
100-
res.send(renderIndex());
101-
} else {
102-
res.redirect('/login');
106+
const { username } = req.user;
107+
return res.redirect(`/${username}/assets`);
103108
}
109+
return res.redirect('/login');
104110
});
105111

106112
router.get('/:username/assets', async (req, res) => {

0 commit comments

Comments
 (0)