Compare commits

...

4 Commits

Author SHA1 Message Date
Shpuld Shpuldson 588c4604af fix leftovers 2021-02-22 17:22:15 +02:00
Shpuld Shpuldson 0c3a215d7e fix tests 2021-02-02 15:18:40 +02:00
Shpuld Shpuldson c0a3ceef00 better error handling 2021-02-01 16:16:41 +02:00
Shpuld Shpuldson 1462404e23 change error handling when request fails, protect routes more in private mode 2021-01-25 18:45:07 +02:00
3 changed files with 34 additions and 16 deletions

View File

@ -22,11 +22,21 @@ import About from 'components/about/about.vue'
import RemoteUserResolver from 'components/remote_user_resolver/remote_user_resolver.vue' import RemoteUserResolver from 'components/remote_user_resolver/remote_user_resolver.vue'
export default (store) => { export default (store) => {
const fallbackRoute = store.state.instance.private ? '/about' : '/main/all'
const validateAuthenticatedRoute = (to, from, next) => { const validateAuthenticatedRoute = (to, from, next) => {
if (store.state.users.currentUser) { if (store.state.users.currentUser) {
next() next()
} else { } else {
next(store.state.instance.redirectRootNoLogin || '/main/all') next(store.state.instance.redirectRootNoLogin || fallbackRoute)
}
}
const validatePrivateRoute = (to, from, next) => {
if (store.state.users.currentUser || !store.state.instance.private) {
next()
} else {
next('/about')
} }
} }
@ -36,15 +46,15 @@ export default (store) => {
redirect: _to => { redirect: _to => {
return (store.state.users.currentUser return (store.state.users.currentUser
? store.state.instance.redirectRootLogin ? store.state.instance.redirectRootLogin
: store.state.instance.redirectRootNoLogin) || '/main/all' : store.state.instance.redirectRootNoLogin) || fallbackRoute
} }
}, },
{ name: 'public-external-timeline', path: '/main/all', component: PublicAndExternalTimeline }, { name: 'public-external-timeline', path: '/main/all', component: PublicAndExternalTimeline, beforeEnter: validatePrivateRoute },
{ name: 'public-timeline', path: '/main/public', component: PublicTimeline }, { name: 'public-timeline', path: '/main/public', component: PublicTimeline, beforeEnter: validatePrivateRoute },
{ name: 'friends', path: '/main/friends', component: FriendsTimeline, beforeEnter: validateAuthenticatedRoute }, { name: 'friends', path: '/main/friends', component: FriendsTimeline, beforeEnter: validateAuthenticatedRoute },
{ name: 'tag-timeline', path: '/tag/:tag', component: TagTimeline }, { name: 'tag-timeline', path: '/tag/:tag', component: TagTimeline, beforeEnter: validatePrivateRoute },
{ name: 'bookmarks', path: '/bookmarks', component: BookmarkTimeline }, { name: 'bookmarks', path: '/bookmarks', component: BookmarkTimeline, beforeEnter: validateAuthenticatedRoute },
{ name: 'conversation', path: '/notice/:id', component: ConversationPage, meta: { dontScroll: true } }, { name: 'conversation', path: '/notice/:id', component: ConversationPage, meta: { dontScroll: true }, beforeEnter: validatePrivateRoute },
{ name: 'remote-user-profile-acct', { name: 'remote-user-profile-acct',
path: '/remote-users/(@?):username([^/@]+)@:hostname([^/@]+)', path: '/remote-users/(@?):username([^/@]+)@:hostname([^/@]+)',
component: RemoteUserResolver, component: RemoteUserResolver,
@ -55,7 +65,7 @@ export default (store) => {
component: RemoteUserResolver, component: RemoteUserResolver,
beforeEnter: validateAuthenticatedRoute beforeEnter: validateAuthenticatedRoute
}, },
{ name: 'external-user-profile', path: '/users/:id', component: UserProfile }, { name: 'external-user-profile', path: '/users/:id', component: UserProfile, beforeEnter: validatePrivateRoute },
{ name: 'interactions', path: '/users/:username/interactions', component: Interactions, beforeEnter: validateAuthenticatedRoute }, { name: 'interactions', path: '/users/:username/interactions', component: Interactions, beforeEnter: validateAuthenticatedRoute },
{ name: 'dms', path: '/users/:username/dms', component: DMs, beforeEnter: validateAuthenticatedRoute }, { name: 'dms', path: '/users/:username/dms', component: DMs, beforeEnter: validateAuthenticatedRoute },
{ name: 'registration', path: '/registration', component: Registration }, { name: 'registration', path: '/registration', component: Registration },
@ -64,12 +74,12 @@ export default (store) => {
{ name: 'friend-requests', path: '/friend-requests', component: FollowRequests, beforeEnter: validateAuthenticatedRoute }, { name: 'friend-requests', path: '/friend-requests', component: FollowRequests, beforeEnter: validateAuthenticatedRoute },
{ name: 'notifications', path: '/:username/notifications', component: Notifications, beforeEnter: validateAuthenticatedRoute }, { name: 'notifications', path: '/:username/notifications', component: Notifications, beforeEnter: validateAuthenticatedRoute },
{ name: 'login', path: '/login', component: AuthForm }, { name: 'login', path: '/login', component: AuthForm },
{ name: 'chat-panel', path: '/chat-panel', component: ChatPanel, props: () => ({ floating: false }) }, { name: 'chat-panel', path: '/chat-panel', component: ChatPanel, props: () => ({ floating: false }), beforeEnter: validateAuthenticatedRoute },
{ name: 'oauth-callback', path: '/oauth-callback', component: OAuthCallback, props: (route) => ({ code: route.query.code }) }, { 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: 'search', path: '/search', component: Search, props: (route) => ({ query: route.query.query }), beforeEnter: validatePrivateRoute },
{ name: 'who-to-follow', path: '/who-to-follow', component: WhoToFollow, beforeEnter: validateAuthenticatedRoute }, { name: 'who-to-follow', path: '/who-to-follow', component: WhoToFollow, beforeEnter: validateAuthenticatedRoute },
{ name: 'about', path: '/about', component: About }, { name: 'about', path: '/about', component: About },
{ name: 'user-profile', path: '/(users/)?:name', component: UserProfile } { name: 'user-profile', path: '/(users/)?:name', component: UserProfile, beforeEnter: validatePrivateRoute }
] ]
if (store.state.instance.pleromaChatMessagesAvailable) { if (store.state.instance.pleromaChatMessagesAvailable) {

View File

@ -563,15 +563,22 @@ const fetchTimeline = ({
}) })
return data return data
}) })
.then((data) => data.json())
.then((data) => { .then((data) => {
if (!data.errors) { if (status >= 500) {
return { data: data.map(isNotifications ? parseNotification : parseStatus), pagination } return { errors: ['Server error'] }
} else { }
return data.json()
})
.then((data) => {
if (status >= 400) {
data.status = status data.status = status
data.statusText = statusText data.statusText = statusText
if (data.error) {
data.errors = [data.error]
}
return data return data
} }
return { data: data.map(isNotifications ? parseNotification : parseStatus), pagination }
}) })
} }

View File

@ -9,7 +9,8 @@ localVue.use(VueRouter)
const store = new Vuex.Store({ const store = new Vuex.Store({
state: { state: {
instance: {} instance: { private: false },
users: {}
} }
}) })