From ff5acba358fcdbc8c527527b20103c412e732320 Mon Sep 17 00:00:00 2001 From: NGPixel Date: Fri, 7 Feb 2020 14:51:11 -0500 Subject: [PATCH] fix: redirect to previous path after login --- client/components/login.vue | 8 +++++++- server/controllers/common.js | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/client/components/login.vue b/client/components/login.vue index 1c3b26e9..94df38ad 100644 --- a/client/components/login.vue +++ b/client/components/login.vue @@ -294,7 +294,13 @@ export default { this.loaderTitle = this.$t('auth:loginSuccess') Cookies.set('jwt', respObj.jwt, { expires: 365 }) _.delay(() => { - window.location.replace('/') // TEMPORARY - USE RETURNURL + const loginRedirect = Cookies.get('loginRedirect') + if (loginRedirect) { + Cookies.remove('loginRedirect') + window.location.replace(loginRedirect) + } else { + window.location.replace('/') + } }, 1000) } } else { diff --git a/server/controllers/common.js b/server/controllers/common.js index 04ba1792..bf7c1265 100644 --- a/server/controllers/common.js +++ b/server/controllers/common.js @@ -245,6 +245,11 @@ router.get('/*', async (req, res, next) => { pageArgs.tags = _.get(page, 'tags', []) if (!WIKI.auth.checkAccess(req.user, ['read:pages'], pageArgs)) { + if (req.user.id === 2) { + res.cookie('loginRedirect', req.path, { + maxAge: 15 * 60 * 1000 + }) + } if (pageArgs.path === 'home' && req.user.id === 2) { return res.redirect('/login') }