Skip to content

Commit

Permalink
feature: redirect if auth/loggedIn getters changes
Browse files Browse the repository at this point in the history
  • Loading branch information
breakingrobot authored and pi0 committed Jan 26, 2018
1 parent 8064839 commit 774fdfa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/templates/auth.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@ export default async function (context, inject) {

// Fetch initial state
await context.store.dispatch('auth/fetch')

// Redirect on login and logout
context.store.watch(() => context.store.getters['auth/loggedIn'], newAuthState =>
{
if (newAuthState) {
context.app.router.replace('<%= options.redirect.loggedIn %>')
return
}

context.app.router.replace('<%= options.redirect.notLoggedIn %>')
})
}

0 comments on commit 774fdfa

Please sign in to comment.