【问题标题】:ember-simple-auth overriding sessionAuthenticatedember-simple-auth 覆盖会话已验证
【发布时间】:2015-12-01 22:10:20
【问题描述】:

伙计们,

我一直试图让 ESA 在登录和注销事件后重定向到特定页面,但没有成功。

我试图通过覆盖“sessionAuthenticated”方法来做到这一点,但也尝试设置“routeAfterConfiguration”设置,但没有成功。

目前,登录将我发送到“/”,注销将应用发送到“/undefined”。

我使用 simple-auth-token 作为 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);
    });
  },
},

});

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

干杯,

安迪

【问题讨论】:

  • 您能发布任何与简单身份验证相关的其他代码吗?您的登录操作、任何自定义身份验证器(或让我们知道您正在使用哪个内置身份验证器)以及与简单身份验证相关的 ENV 配置。你也应该使用this.transitionTo('profile'); 而不是window.location.replace
  • 谢谢汤姆。更多细节在上面编辑...

标签: ember.js login ember-simple-auth


【解决方案1】:

好的。发现了问题。这些不是行动——它们是方法。所以我只需要从动作对象中提升方法就可以了。

所以正确的 routes/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');
  },
});

【讨论】:

  • 啊,我很尴尬没有抓住那个哈哈。很高兴你明白了。
猜你喜欢
  • 1970-01-01
  • 2016-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-04
  • 1970-01-01
相关资源
最近更新 更多