1

I have an Ember application and I use ember-simple-auth for authentication. I want to change the cookie stored, that is related with the authentication, on the fly. The reason is a feature of impersonating another user. I have used

Ember.$.cookie

but it returns "undefined". How could I change the cookie, after I have signed in as user 'X', in order to impersonate user 'Y'?

manosagent
  • 614
  • 8
  • 18

1 Answers1

2

You shouldn't write to the cookie directly as that's maintained by ESA and its contents might change in future versions. Instead you can write to the session data by writing to the session service's data attribute, e.g. this.get('session').set('data.user_id', '<some-user-id>').

It might not be a great idea to identify the current user by some value stored in the session as your users could set that value as well then…

marcoow
  • 4,062
  • 1
  • 14
  • 21
  • i'm doing something like this: `this.get('session').set('data.authenticated.id', this.get('user.id'))`. but the actual cookie value didn't change. any ideas? – RZKY Aug 19 '17 at 09:20
  • You cannot set things inside `data.authenticated`. The fact that the above doesn't trigger an exception is a bug actually. – marcoow Aug 21 '17 at 07:25
  • i end up using the method [described here](https://github.com/simplabs/ember-simple-auth/issues/926#issuecomment-243953558) – RZKY Aug 21 '17 at 08:15