Skip to content

Instantly share code, notes, and snippets.

@mrinterweb
Last active May 21, 2016 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrinterweb/e1574b6c24d961bc8feea4f2dd1ec635 to your computer and use it in GitHub Desktop.
Save mrinterweb/e1574b6c24d961bc8feea4f2dd1ec635 to your computer and use it in GitHub Desktop.
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