ember-simple-auth override session 认证

ember-simple-auth overriding sessionAuthenticated

各位,

我一直在尝试让 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);
    });
  },
},

});

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

干杯,

安迪

好的。发现了问题。这些不是动作——它们是方法。所以我只需要从动作对象中提升方法,一切都很好。

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