Skip to content

Commit 35918e9

Browse files
mfazekasmarcoow
authored andcommitted
Improved current-user and it's loading (mainmatter#1176)
1 parent a5807d9 commit 35918e9

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

guides/managing-current-user.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export default Ember.Service.extend({
7474
return this.get('store').queryRecord('user', { me: true }).then((user) => {
7575
this.set('user', user);
7676
});
77+
} else {
78+
return Ember.RSVP.resolve();
7779
}
7880
}
7981
});
@@ -150,11 +152,11 @@ export default Ember.Route.extend(ApplicationRouteMixin, {
150152

151153
sessionAuthenticated() {
152154
this._super(...arguments);
153-
this._loadCurrentUser().catch(() => this.get('session').invalidate());
155+
this._loadCurrentUser();
154156
},
155157

156158
_loadCurrentUser() {
157-
return this.get('currentUser').load();
159+
return this.get('currentUser').load().catch(() => this.get('session').invalidate());
158160
}
159161
});
160162
```

tests/dummy/app/routes/application.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ export default Route.extend(ApplicationRouteMixin, {
1212

1313
sessionAuthenticated() {
1414
this._super(...arguments);
15-
this._loadCurrentUser().catch(() => this.get('session').invalidate());
15+
this._loadCurrentUser();
1616
},
1717

1818
_loadCurrentUser() {
19-
return this.get('sessionAccount').loadCurrentUser();
19+
return this.get('sessionAccount').loadCurrentUser().catch(() => this.get('session').invalidate());
2020
}
2121
});

0 commit comments

Comments
 (0)