Angular 16 和 Amplify Auth (Cognito) - 配置不正确的错误

问题描述 投票:0回答:1

在配置 Amplify 和 Auth 并传入本页提到的参数时遇到 Amplify 问题:https://docs.amplify.aws/lib/auth/getting-started/q/platform/js/#install-放大库

一切都已正确配置,我可以注册、确认代码并登录,但是当调用 Auth.currentAuthenticatedUser() 时,它会发出错误,指出 Amplify 尚未正确配置。

这是我的配置:

{
    region: 'eu-west-1',
    userPoolWebClientId: 'XXXXXXXXXXXXXXXXXXX',
    userPoolId: 'eu-west-1_XXXXXX',
    oauth: {
      domain: 'https://XXXXXX.auth.eu-west-1.amazoncognito.com',
      scope: ['openid', 'email', 'profile'],
      redirectSignIn: 'http://localhost:4200/',
      redirectSignOut: 'http://localhost:4200/login',
      responseType: 'code',
}

我将其传递给配置函数:

Amplify.configure({
  Auth: env.cognito // The config above,
});

Auth.configure({
  Auth: env.cognito // The config above,
});

如上所述,可以注册、确认代码、登录并接收访问令牌,我的后端服务器正在正常接收访问令牌。正当我想通过 Auth 获取当前经过身份验证的用户时,它却不想玩了。

这是我的package.json:

{
  "name": "@[redacted]/source",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {},
  "private": true,
  "dependencies": {
    "@angular/animations": "~16.2.0",
    "@angular/common": "~16.2.0",
    "@angular/compiler": "~16.2.0",
    "@angular/core": "~16.2.0",
    "@angular/forms": "~16.2.0",
    "@angular/platform-browser": "~16.2.0",
    "@angular/platform-browser-dynamic": "~16.2.0",
    "@angular/router": "~16.2.0",
    "@datorama/akita": "^8.0.1",
    "@nx/angular": "16.7.1",
    "aws-amplify": "^5.3.8",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.13.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~16.2.0",
    "@angular-devkit/core": "~16.2.0",
    "@angular-devkit/schematics": "~16.2.0",
    "@angular-eslint/eslint-plugin": "~16.0.0",
    "@angular-eslint/eslint-plugin-template": "~16.0.0",
    "@angular-eslint/template-parser": "~16.0.0",
    "@angular/cli": "~16.2.0",
    "@angular/compiler-cli": "~16.2.0",
    "@angular/language-service": "~16.2.0",
    "@nx/cypress": "16.7.1",
    "@nx/eslint-plugin": "16.7.1",
    "@nx/jest": "16.7.1",
    "@nx/js": "16.7.1",
    "@nx/linter": "16.7.1",
    "@nx/web": "16.7.1",
    "@nx/workspace": "16.7.1",
    "@schematics/angular": "~16.2.0",
    "@types/jest": "^29.4.0",
    "@types/node": "16.11.7",
    "@typescript-eslint/eslint-plugin": "^5.60.1",
    "@typescript-eslint/parser": "^5.60.1",
    "autoprefixer": "^10.4.0",
    "cypress": "^12.16.0",
    "eslint": "~8.46.0",
    "eslint-config-prettier": "8.1.0",
    "eslint-plugin-cypress": "^2.13.4",
    "jest": "^29.4.1",
    "jest-environment-jsdom": "^29.4.1",
    "jest-preset-angular": "~13.1.0",
    "nx": "16.7.1",
    "nx-cloud": "latest",
    "postcss": "^8.4.5",
    "prettier": "^2.6.2",
    "tailwindcss": "^3.3.3",
    "ts-jest": "^29.1.0",
    "ts-node": "10.9.1",
    "typescript": "~5.1.3"
  }
}

让我知道这里可能出了什么问题,因为我之前已经配置过这个,但使用 Angular 14 并且工作正常,只是工作要求意味着我必须使用 Angular 16。

谢谢。

angular authentication configuration amazon-cognito aws-amplify
1个回答
0
投票

创建服务并将配置添加到构造函数中。这样,每次您调用该服务时,您的 AWS 配置都会被构建。

© www.soinside.com 2019 - 2024. All rights reserved.