Skip to content

Instantly share code, notes, and snippets.

@overture8
Last active December 19, 2015 08:38
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 overture8/5926689 to your computer and use it in GitHub Desktop.
Save overture8/5926689 to your computer and use it in GitHub Desktop.
Ember devise auth
# initializers/current_user.js.coffee
Ember.Application.initializer
name: 'currentUser'
initialize: (container) ->
attributes = $('meta[name="current-user"]').attr('content')
if attributes
json = JSON.parse(attributes)
if attributes
user = App.User.createRecord(email: json.user.email, id: json.user.id)
controller = container.lookup('controller:currentUser').set('content', user)
container.typeInjection('controller', 'currentUser', 'controller:currentUser')
# controllers/current_user_controller.js.coffee
App.CurrentUserController = Ember.ObjectController.extend
isSignedIn: (->
@get('content') != null
).property('@content')
# models/user.js.coffee
App.User = DS.Model.extend
email: DS.attr 'string'
<!-- templates/your_template.handlebars -->
{{#if currentUser}}
<!-- User logged in -->
{{else}}
<!-- User not logged in -->
{{/if}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment