Skip to content

Commit

Permalink
add redirect query param
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa authored and pi0 committed Feb 2, 2018
1 parent b0d2971 commit c5006aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions example/pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<hr>
<b-alert v-model="hasError" dismissible variant="danger">Please check credentials.</b-alert>
<b-alert show v-if="redirect">
You have to login before accessing to this page.
You have to login before accessing to <strong>{{ redirect }}</strong>
</b-alert>
<form @keydown.enter="login">
<b-form-group label="Username">
Expand Down Expand Up @@ -34,7 +34,7 @@ export default {
},
computed: {
redirect() {
return Boolean(this.$route.query.redirect)
return this.$route.query.redirect && decodeURIComponent(this.$route.query.redirect)
}
},
mounted() {
Expand Down
6 changes: 5 additions & 1 deletion lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,18 @@ export default class Auth {
name = this.getState('loggedIn') ? 'home' : 'login'
}

const to = this.options.redirect[name]
let to = this.options.redirect[name]
const from = this.$route.path

// Prevent infinity redirects
if (to.split('?')[0] === from) {
return
}

if (name === 'login' && to.indexOf('?') === -1) {
to = to + '?redirect=' + from
}

this.ctx.redirect(to)
}
}

0 comments on commit c5006aa

Please sign in to comment.