ember-simple-auth覆盖sessionAuthenticated

安迪·戴维森(Andy Davison)

民间,

我一直在尝试使ESA在登录和注销事件后无法成功重定向到特定页面。

我试图通过重写“ sessionAuthenticated”方法来做到这一点,但也尝试设置“ routeAfterConfiguration”设置没有任何运气。

此刻,登录将我发送到“ /”,而注销将应用程序发送到“ / undefined”。

我使用了简单身份验证令牌作为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);
    });
  },
},

});

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

干杯,

安迪

安迪·戴维森(Andy Davison)

好的。找到了问题。这些不是动作-它们是方法。因此,我只需要从动作对象中推广这些方法即可,一切都很好。

因此正确的route / 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');
  },
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Ember ember-simple-auth覆盖routeIfAlreadyAuthenticated在应用程序路由中

来自分类Dev

用ember-simple-auth进行的Ember CLI错误

来自分类Dev

ember-simple-auth和ember-cli

来自分类Dev

使用laravel进行Ember-simple-auth

来自分类Dev

如何使ember-simple-auth会话过期?

来自分类Dev

在Ember Simple Auth中处理多个帐户

来自分类Dev

通过ember-simple-auth登录fb

来自分类Dev

ember-simple-auth和IE

来自分类Dev

Ember-simple-auth即时更改cookie

来自分类Dev

验收测试中的Ember Simple Auth 1.0

来自分类Dev

Ember Simple Auth 1.0测试助手

来自分类Dev

ember-simple-auth密码更新和重置

来自分类Dev

使用Ember Simple Auth访问用户的帐户信息

来自分类Dev

验证后,Ember Simple Auth会进行不同的重定向

来自分类Dev

成功注册后登录Ember-Simple-Auth

来自分类Dev

会话中的ember-simple-auth更新数据

来自分类Dev

Ember-simple-auth获取用户对象嵌套的Promise

来自分类Dev

将Ember_simple_auth与验收测试集成(使用Mirage)

来自分类Dev

如何访问ember-simple-auth中的会话属性?

来自分类Dev

使用ember-cli-simple-auth的多个登录路由

来自分类Dev

使用ember-simple-auth捕获失败的请求

来自分类Dev

更新后的Ember Simple Auth(Devise),验证中断

来自分类Dev

Ember-simple-auth获取用户对象嵌套的Promise

来自分类Dev

成功注册后登录Ember-Simple-Auth

来自分类Dev

Ember CLI Simple Auth ApplicationRouteMixin不会触发操作

来自分类Dev

使用ember-simple-auth捕获失败的请求

来自分类Dev

ember-simple-auth-oauth2会话数据示例

来自分类Dev

无法升级到新的ember-simple-auth

来自分类Dev

在Ember-simple-auth中附加Firebase JWT