Skip to content

Commit

Permalink
fix(auth): start watching loggedIn state after current strategy is fu…
Browse files Browse the repository at this point in the history
…lly mounted (#80)
  • Loading branch information
Pooya Parsa committed May 21, 2018
1 parent 8d96e25 commit 2497cc0
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/core/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@ export default class Auth {
this.$state = storage.state
}

init () {
// Watch for loggedIn changes only in client side
if (process.browser) {
this.$storage.watchState('loggedIn', loggedIn => {
if (!routeOption(this.ctx.route, 'auth', false)) {
this.redirect(loggedIn ? 'home' : 'logout')
}
})
}

async init () {
// Restore strategy
this.$storage.syncUniversal('strategy', this.options.defaultStrategy)

Expand All @@ -46,7 +37,16 @@ export default class Auth {
}

// Call mounted for active strategy on initial load
return this.mounted()
await this.mounted()

// Watch for loggedIn changes only in client side
if (process.browser) {
this.$storage.watchState('loggedIn', loggedIn => {
if (!routeOption(this.ctx.route, 'auth', false)) {
this.redirect(loggedIn ? 'home' : 'logout')
}
})
}
}

// Backward compatibility
Expand Down

0 comments on commit 2497cc0

Please sign in to comment.