Skip to content

Commit

Permalink
fix(auth): handle mounted errors during init (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
gotoin authored and pi0 committed Nov 1, 2018
1 parent eb7dc9e commit 03dba23
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 (error) {
this.callOnError(error)
} finally {
// Watch for loggedIn changes only in client side
if (process.client && 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 03dba23

Please sign in to comment.