diff --git a/CHANGELOG b/CHANGELOG index 3b31937fc6bc63eb69c18af9082e0f0f9c8a9372..d67dac69529796ae0742b6673ede3981b51404b1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ Changelog - Import: can now specify search template when querying import sources (#45) - Player: better handling of errors when fetching the audio file (#46) +- Login form: now redirect to previous page after login (#2) 0.2.4 (2017-12-14) diff --git a/front/src/components/auth/Login.vue b/front/src/components/auth/Login.vue index 867738759f3ef20b6f9d210b827aca876cb27172..54e7b82e096433aacd18d02053e66c164e51ca60 100644 --- a/front/src/components/auth/Login.vue +++ b/front/src/components/auth/Login.vue @@ -43,6 +43,9 @@ import auth from '@/auth' export default { name: 'login', + props: { + next: {type: String} + }, data () { return { // We need to initialize the component with any @@ -69,7 +72,7 @@ export default { } // We need to pass the component's this context // to properly make use of http in the auth service - auth.login(this, credentials, {path: '/library'}, function (response) { + auth.login(this, credentials, {path: this.next}, function (response) { // error callback if (response.status === 400) { self.error = 'invalid_credentials' diff --git a/front/src/main.js b/front/src/main.js index a214c3881e1535178a46a6b1101e2fac17685706..f153635121ececa77e909defc6defccc8d00c938 100644 --- a/front/src/main.js +++ b/front/src/main.js @@ -32,7 +32,7 @@ Vue.http.interceptors.push(function (request, next) { // redirect to login form when we get unauthorized response from server if (response.status === 401) { logger.default.warn('Received 401 response from API, redirecting to login form') - router.push({name: 'login'}) + router.push({name: 'login', query: {next: router.currentRoute.fullPath}}) } }) }) diff --git a/front/src/router/index.js b/front/src/router/index.js index e546172b5f058e0c2ae880be68c82296fc0f41a3..e3d008f5864c691f34fd3d786cdbb5e653a0efd4 100644 --- a/front/src/router/index.js +++ b/front/src/router/index.js @@ -30,7 +30,8 @@ export default new Router({ { path: '/login', name: 'login', - component: Login + component: Login, + props: (route) => ({ next: route.query.next || '/library' }) }, { path: '/logout',