错误 UserUnAuthenticatedException:用户需要经过身份验证才能调用此 API

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

目前我正在实现一个有角度的网站,我使用“aws-amplify/auth”进行身份验证,并使用 localstack 在本地运行 cognito-idp。我登录到我的应用程序,注销后收到此异常“错误 UserUnAuthenticatedException:用户需要经过身份验证才能调用此 API。”

即使我使用“signOut({ global: true });”注销我收到这个错误。我仅在加载或重新加载 AppComponent 时收到此错误。

我已经在网上搜索了此错误,但找不到任何适合我的内容。我已经调试过了,错误是在AppComponent加载后发生的。所以我认为这与组件无关。

我还重建并提供了应用程序,删除了所有浏览器缓存并硬加载了网站。我希望应用程序应该重置并删除“assertAuthTokens”不应失败并返回 false 或类似内容的所有缓存和块。

我正在使用: 操作系统:macOS 14.2.1

npm 列表 -g --深度=0 ├── @angular/[电子邮件受保护] ├── @aws-amplify/[电子邮件受保护] └── [电子邮件受保护]

package-lock.json

  "name": "website",
  "version": "0.0.0",
  "dependencies": {
    "@angular/animations": "^17.1.0",
    "@angular/cdk": "^17.2.1",
    "@angular/common": "^17.1.0",
    "@angular/compiler": "^17.1.0",
    "@angular/core": "^17.1.0",
    "@angular/forms": "^17.1.0",
    "@angular/material": "^17.2.1",
    "@angular/platform-browser": "^17.1.0",
    "@angular/platform-browser-dynamic": "^17.1.0",
    "@angular/router": "^17.1.0",
    "@aws-amplify/ui-angular": "^5.0.11",
    "aws-amplify": "^6.0.18",
    "bootstrap": "^5.3.2",
    "bootstrap-icons": "^1.11.3",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.14.3"

这是我在浏览器中收到的错误日志:

这是扩展的错误:

这是我的 AmplifyConfiguration:

=== main.ts ===
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { appConfig } from './app/app.config';
import { Amplify } from 'aws-amplify';
import { environment } from './environments/environment';

Amplify.configure({
    Auth: {
      Cognito: environment.cognito
    }
  });

bootstrapApplication(AppComponent, appConfig
).catch(err => console.error(err));

=== environment ===
export const environment = {
    production: false,
    apiUrl: 'http://127.0.0.1:3000',
    cognito: {
      region: 'us-east-1',
      userPoolId: 'us-east-1_localuserpool1',
      userPoolClientId: 'localcognitoclient1',
      userPoolEndpoint: 'http://localhost:3000/auth'
    }
  };

预先感谢您的帮助!

angular typescript aws-amplify amplify-auth-cognito
1个回答
0
投票

我不知道这是否有帮助,但在文档中

放大文档

询问必填字段并直接进入 Auth 属性

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