简体   繁体   中英

Ember Simple Auth with Multiple Devise Scopes

I have the following scenario:

  1. Rails app with User and Admin devise models, so I have two scopes.
  2. Created on ember app on router:

     Router.map(function() { this.route('panel', function() { this.route('login'); this.route('logout'); }); this.route('admin', function() { this.route('login'); this.route('logout'); }); }); 
  3. I'm using jj-abrams branch once my app is Ember 2.0

Both authenticating on /users/sign_in and /admins/sign_in

I followed steps on https://github.com/simplabs/ember-simple-auth/tree/master/packages/ember-simple-auth-devise#server-side-setup and authentication is working.

Ember is hitting the right urls after creating authenticators and adapters, but the problem is that ESA just have one session service. Once user or admin is logged in session.isAuthenticated is true and I don't know which scopes are logged in.

Which is the best way to proceed:

  1. Add a role on user reply and set on session
  2. Create a new session for admin user

I solved this problema creating 3 authenticators for each scope, and I handle each one.

It is a particular solution once I don't use other authenticators (OAuth2), but now I can check if authenticator:user , authenticator:admin , authenticator:manager was used on to login.

I have created checks on routes, so user can only access his panel, admin can access user and admin panel, and manager can access the whole system.

I've posted the ember and the API on github:

ps: I think would be better to create sessions for each scope, but I don't know how to do it (and if its better or not), in this solution you can login one scope at once (not like devise on rails you can log with many scopes at once).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM