Skip to content

Commit 2497cc0

Browse files
author
Pooya Parsa
committed
fix(auth): start watching loggedIn state after current strategy is fully mounted (#80)
1 parent 8d96e25 commit 2497cc0

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lib/core/auth.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,7 @@ export default class Auth {
2222
this.$state = storage.state
2323
}
2424

25-
init () {
26-
// Watch for loggedIn changes only in client side
27-
if (process.browser) {
28-
this.$storage.watchState('loggedIn', loggedIn => {
29-
if (!routeOption(this.ctx.route, 'auth', false)) {
30-
this.redirect(loggedIn ? 'home' : 'logout')
31-
}
32-
})
33-
}
34-
25+
async init () {
3526
// Restore strategy
3627
this.$storage.syncUniversal('strategy', this.options.defaultStrategy)
3728

@@ -46,7 +37,16 @@ export default class Auth {
4637
}
4738

4839
// Call mounted for active strategy on initial load
49-
return this.mounted()
40+
await this.mounted()
41+
42+
// Watch for loggedIn changes only in client side
43+
if (process.browser) {
44+
this.$storage.watchState('loggedIn', loggedIn => {
45+
if (!routeOption(this.ctx.route, 'auth', false)) {
46+
this.redirect(loggedIn ? 'home' : 'logout')
47+
}
48+
})
49+
}
5050
}
5151

5252
// Backward compatibility

0 commit comments

Comments
 (0)