Last active
May 21, 2016 01:14
-
-
Save mrinterweb/e1574b6c24d961bc8feea4f2dd1ec635 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export function initialize(appInstance) { | |
appInstance.lookup('service:session').reopen({ | |
isAdmin: Ember.computed('jwt', function() { | |
const isAdmin = this.get('jwt.is_admin'); | |
return (typeof isAdmin === 'boolean') ? isAdmin : false; | |
}), | |
jwt: Ember.computed('data.authenticated.access_token', function() { | |
const accessToken = this.get('data.authenticated.access_token'); | |
if (!Ember.isBlank(accessToken)) { | |
let parts = accessToken.split('.'), | |
json = window.atob(parts[1]), | |
hash = JSON.parse(json); | |
return this.set('jwt', hash); | |
} | |
return {}; | |
}) | |
}); | |
} | |
export default { | |
name: 'extend-session', | |
initialize | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment