@belgoros wrote:
I can’t figure out why flash messsages are displayed whe using in
current-user
service but nothing happens if I move them to the route? Here is the code fromservices/current-user.js
:export default Service.extend({ session: service('session'), store: service(), flashMessages: service('flash-messages'), loadCurrentUser() { this.get('flashMessages').clearMessages(); if (this.get('session.isAuthenticated')) { return this.get('store').queryRecord('user', { me: true }).then((user) => { this.get('flashMessages').success("Signed in successfully !"); this.set('user', user); }); } else { this.get('flashMessages').danger('You are not signed in!'); return RSVP.resolve(); } }
Now if I move the flash from
else
part toapplication.js
router:export default Route.extend(ApplicationRouteMixin, { currentUser: service('current-user'), flashMessages: service('flash-messages'), actions: { logout() { this.get('session').invalidate(); let message = this.get('i18n').t('flash.signed_off'); this.get('flashMessages').danger(message); } }, beforeModel() { return this._loadCurrentUser(); }, sessionAuthenticated() { this._super(...arguments); this._loadCurrentUser(); }, _loadCurrentUser() { return this.get('currentUser').loadCurrentUser().catch(() => this.get('session').invalidate()); }
No errors, nothing at all. Any idea ? Thank you.
Posts: 2
Participants: 1