javascript - aws-amplify with auth 损坏了吗?

标签 javascript reactjs amazon-cognito aws-amplify

我正在尝试构建一个将使用 aws 托管 ui 进行身份验证的 React 应用程序。我正在尝试使用 aws-amplify 来实现这一点,但到目前为止我还没有这样的运气。

Here文档说明身份验证配置应如下所示。

const oauth = {
  domain : 'your-domain-prefix.auth.us-east-1.amazoncognito.com', 
  scope : ['phone', 'email', 'profile', 'openid','aws.cognito.signin.user.admin'], 
  redirectSignIn : 'http://www.example.com/signin/', 
  redirectSignOut : 'http://www.example.com/signout/',
  responseType: 'code',
}

但是当我使用此配置设置时,出现以下错误。

The parameters: App client Id, App web domain, the redirect URL when you are signed in and the redirect URL when you are signed out are required.

如您所见,这些参数已明确提供。因此,我单击了控制台中链接的带有错误消息的源映射文件,并看到了这个。

if (data == null || !ClientId || !AppWebDomain || !RedirectUriSignIn || !RedirectUriSignOut) {
      throw new Error(this.getCognitoConstants().PARAMETERERROR);
    }

这让配置看起来更像这样。

const auth = {
  AppWebDomain: "aaaaa",
  TokenScopesArray: ["phone", "email", "profile", "openid", "aws.cognito.signin.user.admin"],
  RedirectUriSignIn: "http://localhost:3000",
  RedirectUriSignOut: "http://localhost:3000",
  responseType: "token",
  ClientId: "aaa",
  UserPoolId: "aaa",
};

但是当这样做时,并尝试将用户发送到托管用户界面,如文档所说 here我收到此错误。

Uncaught TypeError: Cannot read property 'domain' of undefined

我再次查看源代码并找到了这个。

var domain = config.domain,

这让它看起来像是在期待配置不起作用。

在这一点上,我真的迷路了,需要任何帮助。

最佳答案

通过 Auth.ts 代码,除了 之外,您似乎还必须包含 userPoolIduserPoolWebClientId 字段>oauth。这是我如何让它工作的:

const oauth = {
  domain: 'XXXXXX.auth.us-west-2.amazoncognito.com',
  scope: ['phone', 'email', 'profile', 'openid', 'aws.cognito.signin.user.admin'],
  redirectSignIn: 'http://localhost:3000/',
  redirectSignOut: 'http://localhost:3000/',
  responseType: 'code'
};
Auth.configure({
  oauth: oauth,
  region: 'us-west-2',
  userPoolId: 'us-west-2_XXXXXXXXX',
  userPoolWebClientId: 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
});

关于javascript - aws-amplify with auth 损坏了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54539234/

相关文章:

javascript - 在 map 上渲染多个元素 google-map-react

amazon-web-services - AWS Cognito 自定义页面的空白页面

amazon-web-services - AWS Cognito用户名/电子邮件登录区分大小写

amazon-web-services - 在 Cognito 中哪里可以找到身份池 ID

javascript - 常见的 JavaScript 实现是否使用字符串驻留?

JavaScript 时区偏移与 Windows 偏移不匹配

reactjs - 'x' 类型的 React Typescript 参数不可分配给 'SetStateAction<x]>' 类型的参数

javascript - React Promise 代码需要更改 json 值

Javascript 播放/暂停按钮 键盘事件

javascript - 如何在 React 中使用 i18next 更改语言