【发布时间】:2021-06-17 14:13:23
【问题描述】:
我创建了一个与 Amazon Cognito 集成的 NextJS 应用程序。我有一个使用 Amplify Auth API(不是组件)的登录页面。现在我需要调用外部 API 来执行 CRUD 操作。在 NextJS 中执行此操作的最佳方法是什么?
我想我会在 NextJS 中创建一个 API,它将请求转发到实际的外部 REST API。但我的问题是我无法在 API 上获取 JWT 令牌,因为它是后端代码。
这样的代码:
Auth.currentSession().then(data => console.log(data.accessToken.jwtToken));
显然行不通:
[DEBUG] 20:42.706 AuthClass - Getting current session
[DEBUG] 20:42.706 AuthClass - Failed to get user from user pool
[DEBUG] 20:42.707 AuthClass - Failed to get the current user No current user
(node:20724) UnhandledPromiseRejectionWarning: No current user
如何在 API 中获取令牌?
【问题讨论】:
标签: oauth-2.0 next.js amazon-cognito