简体   繁体   English

ember-simple-auth overriding sessionAuthenticated

[英]ember-simple-auth overriding sessionAuthenticated

Folks, 伙计们,

I've been trying to get ESA to redirect to specific pages after login and logout events without success. 在登录和注销事件后,我一直试图让ESA重定向到特定页面,但没有成功。

I'm trying to do this by overriding the "sessionAuthenticated" method, but have also tried setting the "routeAfterConfiguration" setting with no luck. 我试图通过覆盖“sessionAuthenticated”方法来做到这一点,但也尝试设置“routeAfterConfiguration”设置没有运气。

At the moment, login sends me to "/", and logout sends the app to "/undefined". 此时,登录会将我发送到“/”,然后注销会将应用程序发送到“/ undefined”。

I'm using simple-auth-token as a JWT authenticator strategy. 我使用simple-auth-token作为JWT身份验证器策略。

The code for my application route looks like this... 我的应用程序路由的代码看起来像这样......

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');
     },
   },
});

My login.js is as follows: 我的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);
    });
  },
},

}); });

Does anyone have any idea what I might be doing wrong here? 有谁知道我在这里做错了什么?

Cheers, 干杯,

Andy 安迪

OK. 好。 Found the problem. 发现了问题。 These are not actions - they're methods. 这些不是行动 - 它们是方法。 So I just had to promote the methods out of the actions object and it's all come good. 所以我只需要从动作对象中提升方法,这一切都很好。

So the correct routes/application.js looks like this: 所以正确的路由/ 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