ember-simple-auth覆盖sessionAuthenticated

安迪·戴维森(Andy Davison)

民间,

我一直在尝试使ESA在登录和注销事件后无法成功重定向到特定页面。

我试图通过重写“ sessionAuthenticated”方法来做到这一点,但也尝试设置“ routeAfterConfiguration”设置没有任何运气。

此刻,登录将我发送到“ /”,而注销将应用程序发送到“ / undefined”。

我使用了简单身份验证令牌作为JWT身份验证器策略。

我的应用程序路由的代码如下所示:

import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';

export default Ember.Route.extend(ApplicationRouteMixin,{
    actions: {
      sessionAuthenticated: function() {
         console.log('sessionAuthenticated: authentications ok');
         window.location.replace('/profile');
     },
   },
});

我的login.js如下:

import Ember from 'ember';
const {service} = Ember.inject;

export default Ember.Route.extend({
  session: service('session'),
  errorMessage: null,
  model: function(){
    return Ember.Object.create({
           identification:'', 
           password: '',      
           errorMessage: this.get('errorMessage')
    });
  },

  setupController: function(controller, model) {
    controller.set('credentials',model);
  },

  actions: {
    authenticate: function(credentials) {
      console.log(credentials);
      this.get('session').authenticate('simple-auth-authenticator:jwt', credentials)
    .catch((reason) => {
      console.log('Login Error');
      credentials.set('errorMessage', reason);
    });
  },
},

});

有人知道我在这里可能做错了什么吗?

干杯,

安迪

安迪·戴维森(Andy Davison)

好的。找到了问题。这些不是动作-它们是方法。因此,我只需要从动作对象中推广这些方法即可,一切都很好。

因此正确的route / application.js如下所示:

import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';

export default Ember.Route.extend(ApplicationRouteMixin,{
  sessionAuthenticated: function() {
     console.log('sessionAuthenticated: authentications ok');
     window.location.replace('/profile');
  },
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

ember-simple-auth和ember-cli

Ember Simple Auth 1.0测试助手

Ember-simple-auth即时更改cookie

验收测试中的Ember Simple Auth 1.0

ember-simple-auth和IE

Ember Simple Auth登录错误未显示在页面上

验证后,Ember Simple Auth会进行不同的重定向

ember-simple-auth-oauth2会话数据示例

成功注册后登录Ember-Simple-Auth

Ember-simple-auth获取用户对象嵌套的Promise

Ember Simple Auth - 会话恢复时未设置授权方

无法升级到新的ember-simple-auth

在Ember-simple-auth中附加Firebase JWT

使用ember-simple-auth捕获失败的请求

Ember CLI Simple Auth ApplicationRouteMixin不会触发操作

如何使Ember Cli Mirage与Ember Simple auth一起使用

ember-cli和ember-simple-auth设置用于测试

如何在ember-cli中使用ember-simple-auth?

Ember CLI-在路由中注入服务并使用ember-simple-auth获取当前用户

ember.js + ember-simple-auth认证后如何加载应用程序模型?

ember cli simple auth设计最新版本0.8.0-beta.1

多个身份验证提供程序同时使用 ember-simple-auth

如何在NodeJS端点中访问Ember-Simple-Auth-Token授权者标头

EmberJS:我什么时候应该使用Torii vs Ember-Simple-Auth?

如何使用ember-simple-auth在会话中存储用户ID?

ember-simple-auth-torii Facebook提供者从不返回开放功能的承诺

是否可以使用Ember Simple Auth对所有路由进行身份验证?

为什么在使用ember-simple-auth时还原未发送事件身份验证成功?

Ember-simple-auth,Torii和Facebook Oauth2的工作流程