10

我在 Ember-cli 应用程序中使用Ember Simple Auth Devise v 0.6.4。

我可以正常登录,但是当我刷新页面时会话丢失。(在 Firefox 和 Chrome 中测试。)

登录后立即检查 localStorage 显示会话,刷新后 localStorage 为空。

以下是我登录时本地存储中的内容:

在此处输入图像描述

4

4 回答 4

10

问题是您既没有user_token也没有user_email在会话中需要对会话进行身份验证。因此,一旦您重新加载页面,身份验证器的restore方法就会拒绝会话。同样没有授权user_token也不会实际授权任何请求。user_email

您需要按照此处所述更改服务器端设计设置。

于 2014-08-10T10:27:33.303 回答
2

我在 simple-auth-devise 上遇到了同样的问题。

问题是 in被覆盖config/environment.js了。identificationAttributeName

ENV['simple-auth-devise'] = {
    identificationAttributeName: 'email'
};

通过这样做,它不再匹配Users::SessionsController成功身份验证返回的数据,取自 ember-simple-auth-devise 自述文件:

data = {
    token: user.authentication_token,
    user_email: user.email
}

属性名称必须匹配,因此解决方案是identificationAttributeName在控制器返回的 JSON 中使用:

data = {
    token: user.authentication_token,
    email: user.email
}

就像 marcoow 指出的那样,这一切都在 Devise 授权方restore()方法的实​​现中。

于 2015-03-07T12:30:52.520 回答
0

我遇到了同样的问题,例如,我的会话在刷新时被破坏了。

这是不受欢迎的行为,至少对我来说似乎与服务器端设计设置没有任何关系。

没有请求被发送到服务器,这只是通过使用应该首先检查的 cookie 来保持会话活动的问题。

于 2015-01-19T19:50:46.250 回答
0

我也有这个问题。事实证明,authenticator 中的 restore 方法没有考虑到资源名称。

特别是,更改此处指示的行:https ://github.com/simplabs/ember-simple-auth/blob/master/packages/ember-simple-auth-devise/lib/simple-auth-devise/authenticators/devise .js#L95

如下:

if (!Ember.isEmpty(propertiesObject.get(_this.resourceName)[_this.tokenAttributeName]) && !Ember.isEmpty(propertiesObject.get(_this.resourceName)[_this.identificationAttributeName])) {

解决了这个问题。

请注意,我的本地存储看起来像:

{"secure":{"authenticator":"simple-auth-authenticator:devise","user":{"id":1,"email":"test@gmail.com","created_at":"2015-07-20T22:30:47.966Z","updated_at":"2015-07-23T17:45:41.874Z","authentication_token":"7Uv6LysQ2h3x-P4WUMmU","token":"7Uv6LysQ2h3x-P4WUMmU"}}}

因此,这需要在 config/environment.js 中进行额外的更改

  ENV['simple-auth-devise'] = {
    identificationAttributeName: 'email',
    resourceName: 'user',
    tokenAttributeName: 'authentication_token',
    crossOriginWhitelist: ['*']   
  };

更改 bower_components/ember-simple-auth/simple-auth-devise.amd.js 让我看到这确实是我的问题。

于 2015-07-23T17:56:00.300 回答