Javascript 在具有自定义身份验证存储的服务器上使用AWS Amplify Auth

Javascript 在具有自定义身份验证存储的服务器上使用AWS Amplify Auth,javascript,node.js,reactjs,amazon-cognito,aws-amplify,Javascript,Node.js,Reactjs,Amazon Cognito,Aws Amplify,我有一个服务器端呈现的react应用程序,它调用Amplify的Auth.CurrentAuthenticatedUser方法在显示受保护页面之前检查Auth。 在客户端,我使用cookieStorage。当通过react router的BrowserRouter访问受保护的路由时调用Auth.CurrentAuthenticatedUser时,它可以很好地检索凭据。 在服务器端,当通过直接http调用访问受保护的路由时,我使用以下配置进行放大: import cookie from 'cook

我有一个服务器端呈现的react应用程序,它调用Amplify的Auth.CurrentAuthenticatedUser方法在显示受保护页面之前检查Auth。 在客户端,我使用cookieStorage。当通过react router的BrowserRouter访问受保护的路由时调用Auth.CurrentAuthenticatedUser时,它可以很好地检索凭据。 在服务器端,当通过直接http调用访问受保护的路由时,我使用以下配置进行放大:

import cookie from 'cookie';

class ServerCookieStorage {
  constructor(requestCookie) {
    this.cookieObj = {};
    if (requestCookie) this.cookieObj = cookie.parse(requestCookie);
  }
  setItem(key, value) {
    this.cookieObj[key] = value;
  }
  getItem(key) {
    return this.cookieObj[key];
  }
  removeItem(key) {
    this.cookieObj[key] = '';
  }
}

Amplify.configure({
  Auth: {
    identityPoolId: 'placeholder',
      region: 'placeholder',
      userPoolId: 'placeholder',
      userPoolWebClientId: 'placeholder',
      storage: new ServerCookieStorage(event.headers.Cookie);
      //cookie header in aws lambda functions is located in event.header.Cookie
  }
});
我已经记录了setItem和getItem方法中的内容,当调用Auth.CurrentAuthenticatedUser方法时,它似乎可以很好地检索所有信息,但是该方法失败,错误为未验证

我在这里遗漏了什么吗?

我意识到Auth.CurrentAuthenticatedUser在后台使用了fetch方法,这就是它失败的原因。解决方案是使用node fetch为node提供一个fetch方法polyfill,我是这样做的:

const fetch = require('node-fetch');
global.fetch = fetch;