Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4831

How to wait for a transaction to be finished

$
0
0

@belgoros wrote:

I’m stick with a weird transaction racing when using ESA. I identify a User as follows in current-user service:

loadCurrentUser() {
    this.get('flashMessages').clearMessages();
    if (this.get('session.isAuthenticated')) {
      return this.get('store').queryRecord('user', { me: true }).then((user) => {
        this.get('flashMessages').success(this.get('i18n').t('flash.signed_in'));
        this.get('currentShop').setShop(user.get('shop'));
        this.set('user', user);
      });
    } else {
      this.get('flashMessages').info(this.get('i18n').t('flash.signed_off'));
      return RSVP.resolve();
    }
  }

In application route:

export default Route.extend(ApplicationRouteMixin, {
  currentUser: service('current-user'),

  beforeModel() {
    return this._loadCurrentUser();
  },

  sessionAuthenticated() {
    this._super(...arguments);
    this._loadCurrentUser();
  },

  _loadCurrentUser() {
    return this.get('currentUser').loadCurrentUser().catch(() => this.get('session').invalidate());
  }
});

After authentication I redirect to dashboard route:

#environment.js

ENV['ember-simple-auth'] = {
    routeAfterAuthentication: 'dashboard'
  };

In dashboard route I load shops:

export default Route.extend(AuthenticatedRouteMixin, {
  currentUser: service('current-user'),
  currentShop: service('current-shop'),

  model() {
    return this.store.findAll('shop');
  }
});

What is happening is that I have two end-point hit, both requiring a User to be found or created in the backend based on the data encoded in the token passed in from Ember. How is possible to wait the end of users/me authentication end-point to finish before hitting the dashboard route ? Thank you.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4831

Trending Articles