mardi 28 mai 2019

What is the correct way to set session data with ember-simple-auth

I am using Ember-simple-auth for authentication and have followed this.

My login method looks like this:

authenticate() {
  const { username, password } = this.getProperties('username', 'password');
  this.get('session').authenticate('authenticator:oauth2', username, password).catch((err) => {
    this.set('loginError', 'Login failed: ' + JSON.stringify(err.message));
  })
}

This correctly returns the API token and sets isAuthenticated to True.

My session service uses a computed property to return a promise with the user information like this:

  player: computed('isAuthenticated', function() {
    const userId = this.get('session.content.authenticated._id');
    if (!Ember.isEmpty(userId)) {
      return DS.PromiseObject.create({
        promise: this.get('store').findRecord('user', userId)
      })
    }

I can then access by injecting the session service, but I can't see any session data in my browser. The only thing I can see is ember_simple_auth-session in local storage? How can I extend my own custom class of session data?




Aucun commentaire:

Enregistrer un commentaire