How do I insert a simple authentication session into the adapter?
I have an adapter that requests a url using custom data. I need a way to get data from a simple authentication session to the adapter.
I tried to inject the session into the adapter Adapter
session: Ember.inject.service('session'),
But this throws an error
Error processing route: video.index Attempt to inject unknown injection:
service:session
Error: Attempt to inject unknown injection:service:session
Edit:
In the adapter, I can get user data through the container.
Adapter:
var container = this.get('container');
var currentUser = container.lookup('session:withCurrentUser');
console.log('currentUser ID', currentUser.get('secure.userData.id'));
Is this the recommended way?
+3
source to share
1 answer
You will need first
session: Ember.inject.service(),
Ember knows from the variable name that you need a session service.
Anyway, I would recommend creating an initializer where you inject your session into the adapter.
//initializer/adapter.js
App.inject('adapter', 'session', 'service:session');
+1
source to share