繁体   English   中英

ember-simple-auth overriding sessionAuthenticated

[英]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);
    });
  },
},

});

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

干杯,

安迪

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

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

暂无
暂无

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

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