Skip to content

Instantly share code, notes, and snippets.

@JFickel
Last active December 30, 2015 17:59
Show Gist options
  • Save JFickel/7864982 to your computer and use it in GitHub Desktop.
Save JFickel/7864982 to your computer and use it in GitHub Desktop.
How do I make an Ember initializer for current user? My backend has a /users/current route that simply spits out a serialized current_user. This works, but it fails when there's no current user because Ember tries to build a user model using the nil current_user. Seems kinda messy
Gameway.initializer
name: 'currentUser'
initialize: (container, application) ->
store = container.lookup('store:main')
user = store.find('user', 'current')
# user = Gameway.User.find('current')
container.lookup('controller:currentUser').set('content', user)
container.typeInjection('controller', 'currentUser', 'controller:currentUser')
Gameway.Router.map ()->
@resource 'tournament_membership', { path: "/tournament_memberships/:tournament_membership_id"}
@resource 'user', { path: '/users/:user_id'}
Gameway.User = DS.Model.extend(
username: DS.attr()
first_name: DS.attr()
last_name: DS.attr()
full_name: DS.attr()
avatar_url: DS.attr()
user_url: DS.attr()
lol_account: DS.attr()
starcraft2_account: DS.attr()
)
Gameway.CurrentUserController = Ember.ObjectController.extend
isSignedIn: (->
return this.get('content') && this.get('content').get('isLoaded')
).property('content.isLoaded')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment