简体   繁体   English

Ember引擎和Ember简单Auth

[英]Ember engines and Ember simple Auth

I am implementing ember-engine in my application. 我正在我的应用程序中实现ember-engine。 I am using ember-simple-auth addon for authentication. 我正在使用ember-simple-auth插件进行身份验证。 It works well with main application routes. 它适用于主要的应用程序路线。

I extend the protected routes with mixin provided by addon. 我使用addon提供的mixin扩展受保护的路由。

// app/routes/protected.js
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';

export default Ember.Route.extend(AuthenticatedRouteMixin);

Now I have created a users engine. 现在我创建了一个用户引擎。 which has the userlist and some other stuff. 它有用户列表和其他一些东西。 I want user to access this page only if he is authenticated. 我希望用户只有在经过身份验证后才能访问此页面。 In main app routes I can extend the route with mixin and it will redirect to login route if the user is not authenticated. 在主应用程序路由中,我可以使用mixin扩展路由,如果用户未经过身份验证,它将重定向到登录路由。 But same things does not work with users engine routes. 但同样的事情不适用于用户引擎路由。

Any idea about how to implement Ember-simple-auth with Ember-engines ? 有关如何使用Ember引擎实现Ember-simple-auth的任何想法?

Reference : - 参考: -

Ember engines - https://github.com/ember-engines/ember-engines Ember引擎 - https://github.com/ember-engines/ember-engines

Ember simple auth - https://github.com/simplabs/ember-simple-auth Ember simple auth - https://github.com/simplabs/ember-simple-auth

EDIT- 编辑-

//lib/users-engine/routes/edit.js
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin);

I tried to extend the engines route as above. 我试图像上面那样扩展引擎路线。

Your engine needs to define dependencies it needs the main app to provide. 您的引擎需要定义主应用程序提供的依赖关系。 In your case, you'll need the simple auth service, see Declaring Dependencies for more details. 在您的情况下,您将需要简单的身份验证服务,请参阅声明依赖关系以获取更多详细信息。

https://github.com/ember-engines/ember-engines#declaring-dependencies https://github.com/ember-engines/ember-engines#declaring-dependencies

Note: the mixins that simple auth uses may not work out of the box with this setup (but I think they should). 注意:简单的auth使用的mixin 可能无法使用此设置开箱即用(但我认为应该这样)。 On my phone atm, can look into it later if needed. 在我的手机上,如果需要可以稍后查看。

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

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