Fixed #2: now redirect to previous page after login

This commit is contained in:
Eliot Berriot 2017-12-15 22:23:56 +01:00
parent 6274031f21
commit 80117212b8
No known key found for this signature in database
GPG Key ID: DD6965E2476E5C27
4 changed files with 8 additions and 3 deletions

View File

@ -7,6 +7,7 @@ Changelog
- Import: can now specify search template when querying import sources (#45) - Import: can now specify search template when querying import sources (#45)
- Player: better handling of errors when fetching the audio file (#46) - 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) 0.2.4 (2017-12-14)

View File

@ -43,6 +43,9 @@ import auth from '@/auth'
export default { export default {
name: 'login', name: 'login',
props: {
next: {type: String}
},
data () { data () {
return { return {
// We need to initialize the component with any // We need to initialize the component with any
@ -69,7 +72,7 @@ export default {
} }
// We need to pass the component's this context // We need to pass the component's this context
// to properly make use of http in the auth service // 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 // error callback
if (response.status === 400) { if (response.status === 400) {
self.error = 'invalid_credentials' self.error = 'invalid_credentials'

View File

@ -32,7 +32,7 @@ Vue.http.interceptors.push(function (request, next) {
// redirect to login form when we get unauthorized response from server // redirect to login form when we get unauthorized response from server
if (response.status === 401) { if (response.status === 401) {
logger.default.warn('Received 401 response from API, redirecting to login form') 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}})
} }
}) })
}) })

View File

@ -30,7 +30,8 @@ export default new Router({
{ {
path: '/login', path: '/login',
name: 'login', name: 'login',
component: Login component: Login,
props: (route) => ({ next: route.query.next || '/library' })
}, },
{ {
path: '/logout', path: '/logout',