Handling user authentication when using ember.js

zsquare picture zsquare · May 30, 2012 · Viewed 11.4k times · Source

I was looking up documentation and posts on ember.js, and using ember.js with Rails.

I like the idea of Rails providing the API, and ember.js handling the UI, but I was wondering how to plug User authentication.

Eg, say I am using devise, how do I use it with ember.js?

Any pointers would be much appreciated.

Answer

Jack Johnson picture Jack Johnson · May 30, 2012

Update 2

Check out this new github example app that uses a hybrid rails view + devise-variable-scoped ember app that runs on ember 1.0.rc.1 + ember-data rev 11 and persists has_many relationships.

Check out this token authentication project that isn't quite ready but shows a lot of promise. This could be great for mobile client apis that authenticate users client-side, as opposed to simple web-based rails view devise auth.

Both provide for interesting and debatable use cases. I look forward to seeing where this goes in the future.

Update 1

I added super basic user auth using Devise to Dgeb's ember-data example app here: https://github.com/dgeb/ember_data_example/pull/17 . I used Rails controllers for auth creation and scoping, adding current_user user_id's to the creation of new Contact records, while feeding scoped AMS data to the ember app through current_user.id.


I've had this very same question for a while and the only open-source ember example app I've been able to find that has user authentication and uses rails is https://github.com/carvil/dash-it. He uses a Rails-Devise login view that passes along current_user info to an ember.js app once the user is logged in.

I know many other people use Devise token_authenticatable to completely remove Rails views and authenticate users in Ember apps strictly through tokens. This is probably the best way to go, but I haven't tried implementing it in an app myself yet, and I haven't found any open source apps that go this route.

Tom Dale, one of the lead developers of Ember, says that they don't have a "favored nation" status yet for any specific user auth solution, so until they either officially support a specific solution or build one into the framework, I'm assuming Devise tokens are the best way to go.

Hopefully someone that has more Ember/user auth experience than me can chime in and demonstrate a better solution than https://github.com/carvil/dash-it, using Ember's state machine and routing in combination with token-based user auth.