Tweak custom session
This commit is contained in:
		
							parent
							
								
									1de25effb5
								
							
						
					
					
						commit
						45eca0227c
					
				
					 2 changed files with 14 additions and 16 deletions
				
			
		| 
						 | 
					@ -1,25 +1,11 @@
 | 
				
			||||||
import Session from 'simple-auth/session';
 | 
					 | 
				
			||||||
import parseBase64 from '../utils/parse-base64';
 | 
					 | 
				
			||||||
import Ember from 'ember';
 | 
					import Ember from 'ember';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var CustomSession = Session.extend({
 | 
					 | 
				
			||||||
  currentUser: function() {
 | 
					 | 
				
			||||||
    let token = this.get('secure.token');
 | 
					 | 
				
			||||||
    if (!Ember.isEmpty(token)) {
 | 
					 | 
				
			||||||
      let t = parseBase64(token);
 | 
					 | 
				
			||||||
      return this.container.lookup('service:store').find('user', t['sub']);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return null;
 | 
					 | 
				
			||||||
  }.property('secure.token'),
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export function initialize(container, application) {
 | 
					export function initialize(container, application) {
 | 
				
			||||||
  application.register('session:custom', CustomSession);
 | 
					  application.inject('session:custom', '_store', 'service:store');
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
  name: 'custom-session',
 | 
					  name: 'custom-session',
 | 
				
			||||||
  before: 'simple-auth',
 | 
					  after: 'ember-data',
 | 
				
			||||||
  initialize: initialize
 | 
					  initialize: initialize
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										12
									
								
								app/sessions/custom.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								app/sessions/custom.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,12 @@
 | 
				
			||||||
 | 
					import Session from 'simple-auth/session';
 | 
				
			||||||
 | 
					import parseBase64 from '../utils/parse-base64';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default Session.extend({
 | 
				
			||||||
 | 
					  currentUser: function() {
 | 
				
			||||||
 | 
					    let token = this.get('secure.token');
 | 
				
			||||||
 | 
					    if (token && this.get('isAuthenticated')) {
 | 
				
			||||||
 | 
					      let t = parseBase64(token);
 | 
				
			||||||
 | 
					      return this._store.findRecord('user', t['sub']);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }.property('secure.token', 'isAuthenticated')
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
		Reference in a new issue