8

我正在尝试将 Cognito 设置为使用 cookie 而不是 localStorage 作为凭据,以便我可以让用户在域 egxfoo.com 和 y.foo.com 之间保持登录状态。第一步是让它在本地主机上工作,但我被卡住了。

文档显示一个简单的配置更改应该可以解决问题吗?

以下调试消息被提交到控制台:

[DEBUG] 37:08.223 AuthClass 
Object { idToken: {…}, refreshToken: {…}, accessToken: {…}, clockDrift: 0 }
ConsoleLogger.js:87

[DEBUG] 37:08.228 Credentials - No Cache module registered in Amplify ConsoleLogger.js:84

[DEBUG] 37:08.230 Credentials - set credentials from session ConsoleLogger.js:84

[DEBUG] 37:08.230 Credentials - No Cognito Federated Identity pool provided ConsoleLogger.js:84

[DEBUG] 37:08.230 AuthClass - cannot get cognito credentials No Cognito Federated Identity pool provided ConsoleLogger.js:94

[DEBUG] 37:08.231 AuthClass - Failed to get user from user pool ConsoleLogger.js:84

[ERROR] 37:08.232 AuthClass - Failed to get the signed in user No current user

当您指定 cookieStorage 配置时,您似乎需要手动应用缓存实例?我该怎么做,它会解决问题吗?

4

1 回答 1

10

此配置有效:

{
    region: 'eu-west-1',
    userPoolId: 'eu-west-1_XXXXXX',
    userPoolWebClientId: 'XXXXXX',
    mandatorySignIn: false,
    cookieStorage: {
      domain: 'localhost',
      secure: false,
      path: '/',
      expires: 365,
    },
  }

特别是,localhost除非您使用 https,否则 secure 必须为 false(Firefox 会忽略localhost,但 Chrome 和 Safari 不会)。

于 2020-06-29T20:41:31.463 回答