Skip to content

Commit

Permalink
fix: auth init
Browse files Browse the repository at this point in the history
  • Loading branch information
wade.wei committed Aug 29, 2018
1 parent 315bf4b commit d07c8af
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/core/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,21 @@ export default class Auth {
return Promise.resolve()
}
}

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

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

try {
// Call mounted for active strategy on initial load
await this.mounted()
} catch (e) {

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

Expand Down

0 comments on commit d07c8af

Please sign in to comment.