放大 CLI - Angular + Ionic - MFA - AdminQueries API : XMLHttpRequest.handleError [as __zone_symbol__ON_PROPERTYerror]

Amplify CLI - Angular + Ionic - MFA - AdminQueries API : XMLHttpRequest.handleError [as __zone_symbol__ON_PROPERTYerror]

所以,我使用 Amplify with ionic + angular 并遵循以下 link 和 sublinks,

https://aws-amplify.github.io/docs/js/tutorials/building-ionic-4-apps/

https://aws-amplify.github.io/docs/cli-toolchain/quickstart#administrative-actions

Now, what I want to create is an Admin Panel in my application by which I can create users with MFA enabled for login process (just as it is done via the aws-cognito-console). Therefore, in my form I have provided the email and phone_number as mandatory input fields and for the password I am planning to create an auto-generated one using javascript.

正如我从文档中了解到的那样,这可以通过 AdminQueries API 实现,并且在使用 amplify cli 初始化我的项目时,我进行了所需的配置。结果,我确实在放大后端文件夹中准备好了样板代码,如下面的屏幕所示,

不幸的是,样板代码没有实现 AdminCreateUser 方法,即

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityServiceProvider.html#adminCreateUser-property

因此,我自己在 cognitoActions.js 中创建了这个方法,并且在 app.js 中实现了相同的路由,做了一些 CORS 设置最后做了一个 amplify push

但是当我尝试从 amplify-angular 方法访问这个 api 方法时,它给了我以下错误(我已将错误粘贴在屏幕截图下方)

这就是我在请求、响应中的全部内容 headers,

{"message":"Network Error","name":"Error","stack":"Error: Network Error\n at createError (http://localhost:8100/vendor.js:263903:15)\n at XMLHttpRequest.handleError [as __zone_symbol__ON_PROPERTYerror] (http://localhost:8100/vendor.js:263394:14)\n at XMLHttpRequest.wrapFn (http://localhost:8100/polyfills.js:4541:39)\n at ZoneDelegate.invokeTask (http://localhost:8100/polyfills.js:3741:31)\n at Object.onInvokeTask (http://localhost:8100/vendor.js:70625:33)\n at ZoneDelegate.invokeTask (http://localhost:8100/polyfills.js:3740:60)\n at Zone.runTask (http://localhost:8100/polyfills.js:3518:47)\n at ZoneTask.invokeTask [as invoke] (http://localhost:8100/polyfills.js:3815:34)\n at invokeTask (http://localhost:8100/polyfills.js:4953:14)\n at XMLHttpRequest.globalZoneAwareCallback (http://localhost:8100/polyfills.js:4979:17)","config":{"url":"https://4wdmydkl7e.execute-api.ap-south-1.amazonaws.com/test/addUser","method":"post","data":"{\"user\":{\"firstname\":\"Prateek\",\"lastname\":\"k\",\"email\":\"opensource.prateek@gmail.com\",\"phoneNumber\":\"+918700416661\",\"specialization\":\"instrumentation\",\"role\":\"admin\"}}","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json"},"transformRequest":[null],"transformResponse":[null],"timeout":0,"responseType":"json","xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"host":"4wdmydkl7e.execute-api.ap-south-1.amazonaws.com","path":"/test/addUser"}}

----更新 1 -----

我已将以下内容添加到我的 polyfills.js、

(window as any).global = window;
(window as any).process = {
  env: { DEBUG: undefined },
};

这是给我的 index.html

<script>
  if (global === undefined) {
    var global = window;
  }
</script>

所以我做了一个放大删除,即从我的 angular 2 项目中删除放大并移动到 nodejs aws sdk,在我的无服务器后端代码中以及现有的 lambda 函数现在我有更多使用以下管理查询 API、

创建、删除和列出用户的 lambda

https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AddCustomAttributes.html

Amplify 的文档仍然损坏,因此,我建议使用上面 link 中提到的更强大的 API / SDK。