简体   繁体   English

ember.js:从AuthenticatedRouteMixin中创建AdminRouteMixin吗?

[英]ember.js: Make AdminRouteMixin from AuthenticatedRouteMixin?

Is there a more elegant way to prevent unauthorized access to an admin-only route than writing this in all of my admin routes? 有没有比在我所有的管理路由中都写出的更优雅的方法来防止对仅管理路由的未授权访问?

export default Ember.Route.extend(AuthenticatedRouteMixin, {
  beforeModel: function(){
    if(!this.get('session.secure.admin')) this.transitionTo("dashboard");
  }
});

Perhaps it's possible to extend AuthenticatedRouteMixin itself to make this kind of check? 也许可以扩展AuthenticatedRouteMixin本身来进行这种检查? Thanks! 谢谢!

Why not just make the mixin? 为什么不只做混合呢?

import Ember from 'ember';
import AuthenticatedRouteMixin from 'wherever/it/is'.

const { Mixin } = Ember;

export default Mixin.create(AuthenticatedRouteMixin, {
  beforeModel(){
    if(!this.get('session.secure.admin')) {
      this.transitionTo("dashboard");
    }
  }
})

And then import it in your routes: 然后将其导入您的路线中:

import Ember from 'ember';
import AdminCheckMixin from 'yourApp/mixins/routes/admin-check';

const { Route } = Ember;

export default Route.extend(AdminCheckMixin);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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