Upgrading authentication libs
This commit is contained in:
		
							parent
							
								
									878e8d1b60
								
							
						
					
					
						commit
						459bd7d6be
					
				
					 7 changed files with 36 additions and 30 deletions
				
			
		| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
// from: http://blog.willrax.com/fetching-the-current-user-with-simple-auth/
 | 
			
		||||
import Ember from "ember";
 | 
			
		||||
import DS from 'ember-data';
 | 
			
		||||
import Session from "simple-auth/session";
 | 
			
		||||
 | 
			
		||||
// This is pulled straight from ember-cli-simple-auth-token
 | 
			
		||||
| 
						 | 
				
			
			@ -12,22 +12,23 @@ function getTokenData(token) {
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var CustomSession = Session.extend({
 | 
			
		||||
  currentUser: function() {
 | 
			
		||||
    let token = this.get('secure.token');
 | 
			
		||||
    if (!Ember.isEmpty(token)) {
 | 
			
		||||
      let t = getTokenData(token);
 | 
			
		||||
      return DS.PromiseObject.create({
 | 
			
		||||
        promise: this.container.lookup('store:main').find('user', t['sub'])
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
    return null;
 | 
			
		||||
  }.property('token')
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
  name: "custom-session",
 | 
			
		||||
  before: "simple-auth",
 | 
			
		||||
  initialize: function(container) {
 | 
			
		||||
    Session.reopen({
 | 
			
		||||
      setCurrentUser: function() {
 | 
			
		||||
        var token = this.get("token");
 | 
			
		||||
        var self = this;
 | 
			
		||||
 | 
			
		||||
        if (!Ember.isEmpty(token)) {
 | 
			
		||||
          var t = getTokenData(token);
 | 
			
		||||
          return container.lookup("store:main").find("user", t['sub']).then(function(user) {
 | 
			
		||||
            self.set("currentUser", user);
 | 
			
		||||
          });
 | 
			
		||||
        }
 | 
			
		||||
      }.observes("token")
 | 
			
		||||
    });
 | 
			
		||||
  initialize: function(container, application) {
 | 
			
		||||
    application.register('session:custom', CustomSession);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue