簡體   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