From ad29e20324f8af519b60b2920a352096346230be Mon Sep 17 00:00:00 2001
From: taehoon
Date: Tue, 23 Jul 2019 20:54:15 -0400
Subject: [PATCH 1/2] guard secure routes by redirecting to root
---
src/boot/routes.js | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/boot/routes.js b/src/boot/routes.js
index 22641f833b..3639fcbf0f 100644
--- a/src/boot/routes.js
+++ b/src/boot/routes.js
@@ -19,6 +19,14 @@ import WhoToFollow from 'components/who_to_follow/who_to_follow.vue'
import About from 'components/about/about.vue'
export default (store) => {
+ const validateAuthenticatedRoute = (to, from, next) => {
+ if (store.state.users.currentUser) {
+ next()
+ } else {
+ next(store.state.instance.redirectRootNoLogin || '/main/all')
+ }
+ }
+
return [
{ name: 'root',
path: '/',
@@ -30,17 +38,17 @@ export default (store) => {
},
{ name: 'public-external-timeline', path: '/main/all', component: PublicAndExternalTimeline },
{ name: 'public-timeline', path: '/main/public', component: PublicTimeline },
- { name: 'friends', path: '/main/friends', component: FriendsTimeline },
+ { name: 'friends', path: '/main/friends', component: FriendsTimeline, beforeEnter: validateAuthenticatedRoute },
{ name: 'tag-timeline', path: '/tag/:tag', component: TagTimeline },
{ name: 'conversation', path: '/notice/:id', component: ConversationPage, meta: { dontScroll: true } },
{ name: 'external-user-profile', path: '/users/:id', component: UserProfile },
- { name: 'interactions', path: '/users/:username/interactions', component: Interactions },
- { name: 'dms', path: '/users/:username/dms', component: DMs },
+ { name: 'interactions', path: '/users/:username/interactions', component: Interactions, beforeEnter: validateAuthenticatedRoute },
+ { name: 'dms', path: '/users/:username/dms', component: DMs, beforeEnter: validateAuthenticatedRoute },
{ name: 'settings', path: '/settings', component: Settings },
{ name: 'registration', path: '/registration', component: Registration },
{ name: 'registration-token', path: '/registration/:token', component: Registration },
- { name: 'friend-requests', path: '/friend-requests', component: FollowRequests },
- { name: 'user-settings', path: '/user-settings', component: UserSettings },
+ { name: 'friend-requests', path: '/friend-requests', component: FollowRequests, beforeEnter: validateAuthenticatedRoute },
+ { name: 'user-settings', path: '/user-settings', component: UserSettings, beforeEnter: validateAuthenticatedRoute },
{ name: 'notifications', path: '/:username/notifications', component: Notifications },
{ name: 'login', path: '/login', component: AuthForm },
{ name: 'chat', path: '/chat', component: ChatPanel, props: () => ({ floating: false }) },
From 8375d7a3aa198c77732beda535fe92b9ffbe4356 Mon Sep 17 00:00:00 2001
From: taehoon
Date: Tue, 23 Jul 2019 21:52:24 -0400
Subject: [PATCH 2/2] guard more secure routes
---
src/boot/routes.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/boot/routes.js b/src/boot/routes.js
index 3639fcbf0f..7dc4b2a5da 100644
--- a/src/boot/routes.js
+++ b/src/boot/routes.js
@@ -49,12 +49,12 @@ export default (store) => {
{ name: 'registration-token', path: '/registration/:token', component: Registration },
{ name: 'friend-requests', path: '/friend-requests', component: FollowRequests, beforeEnter: validateAuthenticatedRoute },
{ name: 'user-settings', path: '/user-settings', component: UserSettings, beforeEnter: validateAuthenticatedRoute },
- { name: 'notifications', path: '/:username/notifications', component: Notifications },
+ { name: 'notifications', path: '/:username/notifications', component: Notifications, beforeEnter: validateAuthenticatedRoute },
{ name: 'login', path: '/login', component: AuthForm },
{ name: 'chat', path: '/chat', component: ChatPanel, props: () => ({ floating: false }) },
{ name: 'oauth-callback', path: '/oauth-callback', component: OAuthCallback, props: (route) => ({ code: route.query.code }) },
{ name: 'search', path: '/search', component: Search, props: (route) => ({ query: route.query.query }) },
- { name: 'who-to-follow', path: '/who-to-follow', component: WhoToFollow },
+ { name: 'who-to-follow', path: '/who-to-follow', component: WhoToFollow, beforeEnter: validateAuthenticatedRoute },
{ name: 'about', path: '/about', component: About },
{ name: 'user-profile', path: '/(users/)?:name', component: UserProfile }
]