0

I'm trying to use a service, let's say for User Login session. I retrieve the user's info from the service.

Now I want to display this info - ideally using a model (user-profile).

My question is, in my service - can I set the user-profile model's attributes? So that my "profile-view" route can show the data in the user-profile model.

Put Time
  • 71
  • 6

1 Answers1

0

You could inject the store service, retrieve a record and change it.

import Service from '@ember/service';

export default Service.extend({
  afterLogin(userId, sessionData) {
    let store = this.get('store');
    let userProfile = store.peekRecord('user-profile', userId);
    userProfile.set('foo', sessionData.foo);
  },
  store: service(),
});

But I don't understand why you want to set session related data on a model record. If it's just about consuming the data associated with session, you could import your service where needed and access it directly. If user profile needs to be updated after login (e.g. setting a last login property), api should be responsible for that in my opinion.

jelhan
  • 6,149
  • 1
  • 19
  • 35