Serverside fetchAuthSession suddenly stopped returning tokens in local development
Before opening, please confirm:
- [x] I have searched for duplicate or closed issues and discussions.
- [x] I have read the guide for submitting bug reports.
- [x] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
React, Next.js
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
Other
Environment information
# Put output below this line
System:
OS: macOS 15.3.2
CPU: (10) arm64 Apple M2 Pro
Memory: 177.64 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v20.10.0/bin/yarn
npm: 10.9.2 - ~/.nvm/versions/node/v20.10.0/bin/npm
Watchman: 2023.08.28.00 - /opt/homebrew/bin/watchman
Browsers:
Brave Browser: 118.1.59.117
Chrome: 137.0.7151.120
Safari: 18.3.1
npmPackages:
@ampproject/toolbox-optimizer: undefined ()
@apollo/client: ^3.13.8 => 3.13.8
@apollo/client-integration-nextjs: ^0.12.2 => 0.12.2
@apollo/client/cache: undefined ()
@apollo/client/core: undefined ()
@apollo/client/dev: undefined ()
@apollo/client/errors: undefined ()
@apollo/client/link/batch: undefined ()
@apollo/client/link/batch-http: undefined ()
@apollo/client/link/context: undefined ()
@apollo/client/link/core: undefined ()
@apollo/client/link/error: undefined ()
@apollo/client/link/http: undefined ()
@apollo/client/link/persisted-queries: undefined ()
@apollo/client/link/remove-typename: undefined ()
@apollo/client/link/retry: undefined ()
@apollo/client/link/schema: undefined ()
@apollo/client/link/subscriptions: undefined ()
@apollo/client/link/utils: undefined ()
@apollo/client/link/ws: undefined ()
@apollo/client/masking: undefined ()
@apollo/client/react: undefined ()
@apollo/client/react/components: undefined ()
@apollo/client/react/context: undefined ()
@apollo/client/react/hoc: undefined ()
@apollo/client/react/hooks: undefined ()
@apollo/client/react/internal: undefined ()
@apollo/client/react/parser: undefined ()
@apollo/client/react/ssr: undefined ()
@apollo/client/testing: undefined ()
@apollo/client/testing/core: undefined ()
@apollo/client/testing/experimental: undefined ()
@apollo/client/utilities: undefined ()
@apollo/client/utilities/globals: undefined ()
@apollo/client/utilities/subscriptions/relay: undefined ()
@apollo/client/utilities/subscriptions/urql: undefined ()
@aws-amplify/adapter-nextjs: ^1.6.4 => 1.6.4
@aws-amplify/adapter-nextjs/api: undefined ()
@aws-amplify/adapter-nextjs/data: undefined ()
@babel/core: undefined ()
@babel/runtime: 7.22.5
@edge-runtime/cookies: 6.0.0
@edge-runtime/ponyfill: 4.0.0
@edge-runtime/primitives: 6.0.0
@emotion/react: ^11.13.5 => 11.14.0
@emotion/styled: ^11.13.5 => 11.14.0
@googlemaps/places: ^2.0.1 => 2.0.1
@graphql-codegen/cli: ^5.0.3 => 5.0.3
@habx/apollo-multi-endpoint-link: ^2.9.0 => 2.9.0
@hapi/accept: undefined ()
@hookform/resolvers: ^3.9.1 => 3.9.1
@hookform/resolvers/ajv: 1.0.0
@hookform/resolvers/arktype: 2.0.0
@hookform/resolvers/class-validator: 1.0.0
@hookform/resolvers/computed-types: 1.0.0
@hookform/resolvers/effect-ts: 1.0.0
@hookform/resolvers/fluentvalidation-ts: 1.0.0
@hookform/resolvers/io-ts: 1.0.0
@hookform/resolvers/joi: 1.0.0
@hookform/resolvers/nope: 1.0.0
@hookform/resolvers/superstruct: 1.0.0
@hookform/resolvers/typanion: 1.0.0
@hookform/resolvers/typebox: 1.0.0
@hookform/resolvers/typeschema: 1.0.0
@hookform/resolvers/valibot: 1.0.0
@hookform/resolvers/vest: 1.0.0
@hookform/resolvers/vine: 1.0.0
@hookform/resolvers/yup: 1.0.0
@hookform/resolvers/zod: 1.0.0
@mswjs/interceptors: undefined ()
@mui/icons-material: ^6.1.10 => 6.2.0
@mui/material: ^6.1.9 => 6.2.0
@mui/material-nextjs: ^6.1.9 => 6.2.0
@mui/x-date-pickers: ^7.28.0 => 7.28.0
@napi-rs/triples: undefined ()
@next/font: undefined ()
@next/third-parties: ^15.3.0 => 15.3.0
@opentelemetry/api: undefined ()
@react-oauth/google: ^0.12.1 => 0.12.1
@stripe/react-stripe-js: ^3.1.1 => 3.1.1
@stripe/stripe-js: ^5.3.0 => 5.3.0
@tanstack/query-codemods: undefined ()
@tanstack/react-query: ^5.62.8 => 5.62.8
@types/geojson: ^7946.0.15 => 7946.0.15
@types/lodash.debounce: ^4.0.9 => 4.0.9
@types/lodash.get: ^4.4.9 => 4.4.9
@types/lodash.maxby: ^4.6.9 => 4.6.9
@types/lodash.omit: ^4.5.9 => 4.5.9
@types/lodash.uniqby: ^4.7.9 => 4.7.9
@types/luxon: ^3.4.2 => 3.4.2
@types/node: ^20 => 20.17.10
@types/react: 19.0.12 => 19.0.12
@types/react-big-calendar: ^1.16.0 => 1.16.0
@types/react-dom: 19.0.4 => 19.0.4
@types/react-lottie: ^1.2.10 => 1.2.10
@types/react-scroll: ^1.8.10 => 1.8.10
@types/uuid: ^10.0.0 => 10.0.0 (9.0.8)
@vercel/nft: undefined ()
@vercel/og: 0.6.5
@vis.gl/react-google-maps: ^1.4.2 => 1.4.2
acorn: undefined ()
ajv: ^8.17.1 => 8.17.1 (6.12.6)
amphtml-validator: undefined ()
anser: undefined ()
assert: undefined ()
async-retry: undefined ()
async-sema: undefined ()
aws-amplify: ^6.15.1 => 6.15.1
aws-amplify/adapter-core: undefined ()
aws-amplify/adapter-core/internals: undefined ()
aws-amplify/analytics: undefined ()
aws-amplify/analytics/kinesis: undefined ()
aws-amplify/analytics/kinesis-firehose: undefined ()
aws-amplify/analytics/personalize: undefined ()
aws-amplify/analytics/pinpoint: undefined ()
aws-amplify/api: undefined ()
aws-amplify/api/internals: undefined ()
aws-amplify/api/server: undefined ()
aws-amplify/auth: undefined ()
aws-amplify/auth/cognito: undefined ()
aws-amplify/auth/cognito/server: undefined ()
aws-amplify/auth/enable-oauth-listener: undefined ()
aws-amplify/auth/server: undefined ()
aws-amplify/data: undefined ()
aws-amplify/data/server: undefined ()
aws-amplify/datastore: undefined ()
aws-amplify/in-app-messaging: undefined ()
aws-amplify/in-app-messaging/pinpoint: undefined ()
aws-amplify/push-notifications: undefined ()
aws-amplify/push-notifications/pinpoint: undefined ()
aws-amplify/storage: undefined ()
aws-amplify/storage/s3: undefined ()
aws-amplify/storage/s3/server: undefined ()
aws-amplify/storage/server: undefined ()
aws-amplify/utils: undefined ()
babel-packages: undefined ()
browserify-zlib: undefined ()
browserslist: undefined ()
buffer: undefined ()
bytes: undefined ()
ci-info: undefined ()
cli-select: undefined ()
client-only: 0.0.1
commander: undefined ()
comment-json: undefined ()
compression: undefined ()
conf: undefined ()
constants-browserify: undefined ()
content-disposition: undefined ()
content-type: undefined ()
cookie: undefined ()
cross-spawn: undefined ()
crypto-browserify: undefined ()
css.escape: undefined ()
currency-symbol-map: ^5.1.0 => 5.1.0
data-uri-to-buffer: undefined ()
debug: undefined ()
devalue: undefined ()
domain-browser: undefined ()
edge-runtime: undefined ()
eslint: ^8 => 8.57.1
eslint-config-next: 15.2.4 => 15.2.4
eslint-config-prettier: ^9.1.0 => 9.1.0
events: undefined ()
find-up: undefined ()
fresh: undefined ()
get-user-locale: ^3.0.0 => 3.0.0
glob: undefined ()
graphql: ^16.9.0 => 16.9.0 (15.8.0)
gzip-size: undefined ()
http-proxy: undefined ()
http-proxy-agent: undefined ()
https-browserify: undefined ()
https-proxy-agent: undefined ()
icss-utils: undefined ()
ignore-loader: undefined ()
image-size: undefined ()
is-animated: undefined ()
is-docker: undefined ()
is-wsl: undefined ()
jest-worker: undefined ()
json5: undefined ()
jsonwebtoken: undefined ()
loader-runner: undefined ()
loader-utils: undefined ()
locale-code: ^2.0.2 => 2.0.2
lodash.curry: undefined ()
lodash.debounce: ^4.0.8 => 4.0.8
lodash.get: ^4.4.2 => 4.4.2
lodash.maxby: ^4.6.0 => 4.6.0
lodash.omit: ^4.5.0 => 4.5.0
lodash.uniqby: ^4.7.0 => 4.7.0
lru-cache: undefined ()
luxon: ^3.5.0 => 3.5.0
mini-css-extract-plugin: undefined ()
nanoid: undefined ()
native-url: undefined ()
neo-async: undefined ()
next: 15.2.4 => 15.2.4
next-sitemap: ^4.2.3 => 4.2.3
node-html-parser: undefined ()
notistack: ^3.0.2 => 3.0.2
ora: undefined ()
os-browserify: undefined ()
p-limit: undefined ()
p-queue: undefined ()
path-browserify: undefined ()
path-to-regexp: undefined ()
picomatch: undefined ()
postcss-flexbugs-fixes: undefined ()
postcss-modules-extract-imports: undefined ()
postcss-modules-local-by-default: undefined ()
postcss-modules-scope: undefined ()
postcss-modules-values: undefined ()
postcss-preset-env: undefined ()
postcss-safe-parser: undefined ()
postcss-scss: undefined ()
postcss-value-parser: undefined ()
prettier: ^3.4.1 => 3.4.2
process: undefined ()
punycode: undefined ()
querystring-es3: undefined ()
raw-body: undefined ()
react: 19.0.0 => 19.0.0
react-big-calendar: ^1.18.0 => 1.18.0
react-builtin: undefined ()
react-day-picker: ^9.4.2 => 9.4.3
react-dnd: ^16.0.1 => 16.0.1
react-dnd-html5-backend: ^16.0.1 => 16.0.1
react-dom: 19.0.0 => 19.0.0
react-dom-builtin: undefined ()
react-dom-experimental-builtin: undefined ()
react-experimental-builtin: undefined ()
react-hook-form: ^7.53.2 => 7.54.0
react-is: 19.1.0-canary-029e8bd6-20250306
react-lottie: ^1.2.10 => 1.2.10
react-refresh: 0.12.0
react-scroll: ^1.9.3 => 1.9.3
react-server-dom-turbopack-builtin: undefined ()
react-server-dom-turbopack-experimental-builtin: undefined ()
react-server-dom-webpack-builtin: undefined ()
react-server-dom-webpack-experimental-builtin: undefined ()
react-svg-credit-card-payment-icons: ^3.1.1 => 3.1.1
regenerator-runtime: 0.13.4
sass-loader: undefined ()
scheduler-builtin: undefined ()
scheduler-experimental-builtin: undefined ()
schema-dts: ^1.1.2 => 1.1.2
schema-utils: undefined ()
semver: undefined ()
send: undefined ()
server-only: 0.0.1
setimmediate: undefined ()
sharp: ^0.33.5 => 0.33.5
shell-quote: undefined ()
source-map: undefined ()
source-map08: undefined ()
stacktrace-parser: undefined ()
stream-browserify: undefined ()
stream-chat: ^9.0.4 => 9.4.0
stream-chat-react: ^13.0.5 => 13.0.5
stream-http: undefined ()
string-hash: undefined ()
string_decoder: undefined ()
strip-ansi: undefined ()
superstruct: undefined ()
swiper: ^11.2.5 => 11.2.5
tar: undefined ()
terser: undefined ()
text-table: undefined ()
timers-browserify: undefined ()
tty-browserify: undefined ()
typescript: ^5 => 5.7.2
ua-parser-js: undefined ()
unistore: undefined ()
usehooks-ts: ^3.1.1 => 3.1.1
util: undefined ()
uuid: ^11.0.5 => 11.0.5 (9.0.1)
vm-browserify: undefined ()
watchpack: undefined ()
web-vitals: undefined ()
webpack: undefined ()
webpack-sources: undefined ()
ws: undefined ()
zod: ^3.23.8 => 3.24.1 ()
zod-validation-error: undefined ()
npmGlobalPackages:
@coach-squad/base-emails: 3.2.0
@crimson-education/rv-api-base: 3.5.4
@crimson-education/rv-markdown-ex: 1.0.33
@eslint/migrate-config: 1.2.0
@openai/codex: 0.1.2505191453
corepack: 0.22.0
create-react-admin: 4.16.16
npm: 10.9.2
react-dom: 18.1.0
react: 18.1.0
test-admin: 1.0.0
yarn: 1.22.22
Describe the bug
I am using the next-js adapter for serverside and clientside authentication in my next-js app. I am confident I have set it up correctly and in fact this works perfectly well in production.
However, for the last 2 or 3 days, tokens are no longer returned in local development when fetching them from the serverside (I haven't changed anything recently other than move somewhere with slightly worse internet). I have looked through the other issues https://github.com/aws-amplify/amplify-js/issues/14350 and https://github.com/aws-amplify/amplify-js/issues/13456 but they do not explain why I am seeing this only locally.
Expected behavior
Tokens should be returned in my dev environment the same way they are returned in production environments.
Reproduction steps
- In a page.tsx file try to fetch the token and it is not returned
serverside.ts
import { cookies } from "next/headers";
import { createServerRunner } from "@aws-amplify/adapter-nextjs";
import { fetchAuthSession } from "aws-amplify/auth/server";
import { amplifyConfig } from "./config";
export const { runWithAmplifyServerContext } = createServerRunner({
config: amplifyConfig,
});
export async function getTokensServerside() {
try {
const session = await runWithAmplifyServerContext({
nextServerContext: { cookies },
operation: async (contextSpec) => {
const session = await fetchAuthSession(contextSpec);
return session;
},
});
const token = session.tokens?.accessToken.toString();
return {
accessToken: token ?? "none",
isAuthenticated: !!token,
};
} catch {
return {
accessToken: "none",
isAuthenticated: false,
};
}
}
import { RedirectType, redirect } from "next/navigation";
import { getTokensServerside } from "@/amplify/serverside";
import { LoginForm } from "./components/LoginForm";
import type { Metadata } from "next";
import { getClient } from "@/api/rscClient";
import { GetMe } from "@/api/usersAndLocations/graphql";
export const dynamic = "force-dynamic";
export default async function Page(props: {
searchParams: Promise<{
from: string | undefined;
encoded: string | undefined;
}>;
}) {
const searchParams = await props.searchParams;
const [{ from: fromParam, encoded }, { isAuthenticated }] = await Promise.all(
[searchParams, getTokensServerside()],
);
if (isAuthenticated) {
/// .. other stuff
}
}
Code Snippet
My setup using the app router:
serverside.ts
import { cookies } from "next/headers";
import { createServerRunner } from "@aws-amplify/adapter-nextjs";
import { fetchAuthSession } from "aws-amplify/auth/server";
import { amplifyConfig } from "./config";
export const { runWithAmplifyServerContext } = createServerRunner({
config: amplifyConfig,
});
export async function getTokensServerside() {
try {
const session = await runWithAmplifyServerContext({
nextServerContext: { cookies },
operation: async (contextSpec) => {
const session = await fetchAuthSession(contextSpec);
return session;
},
});
const token = session.tokens?.accessToken.toString();
return {
accessToken: token ?? "none",
isAuthenticated: !!token,
};
} catch {
return {
accessToken: "none",
isAuthenticated: false,
};
}
}
clientside.tsx
"use client";
import { Amplify } from "aws-amplify";
import { amplifyConfig } from "./config";
Amplify.configure(amplifyConfig, { ssr: true });
export default function ConfigureAmplifyClientSide({
children,
}: {
children: React.ReactNode;
}) {
return children;
}
my root layout
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={`${inter.variable} ${asimov.variable}`}>
<Providers>{children}</Providers>
</body>
</html>
);
}
providers.tsx
"use client";
import { FC, ReactNode } from "react";
import { AppRouterCacheProvider } from "@mui/material-nextjs/v15-appRouter";
import ConfigureAmplifyClientSide from "@/amplify/clientside";
export const Providers: FC<{ children: ReactNode }> = ({ children }) => {
return (
<ConfigureAmplifyClientSide>
<AppRouterCacheProvider>
// other providers
{children}
</AppRouterCacheProvider>
</ConfigureAmplifyClientSide>
);
};
Log output
logging: { fetches: { fullUrl: true, }, }
I see that the requests take a long time. I suspect they may be timing out, but I have no way to check this.
│ POST https://cognito-identity.us-east-1.amazonaws.com/ 200 in 2654ms (cache skip)
│ │ Cache skipped reason: (cache: no-store)
│ POST https://cognito-identity.us-east-1.amazonaws.com/ 200 in 3102ms (cache skip)
│ │ Cache skipped reason: (cache: no-store)
I can confirm that the cookies are available in the serverside e.g. if i add logging for the cookies
const session = await runWithAmplifyServerContext({
nextServerContext: { cookies },
operation: async (contextSpec) => {
const cookieLog = await cookies()
console.log(cookieLog)
const session = await fetchAuthSession(contextSpec);
return session;
}
i can see the cookies
'CognitoIdentityServiceProvider.4joc7jl09rf6fmmmnqnvfohqo9.LastAuthUser' => {
name: 'CognitoIdentityServiceProvider.4joc7jl09rf6fmmmnqnvfohqo9.LastAuthUser',
value: '4bab76f8-d325-4501-9e13-1f98e21a8078'
},
'CognitoIdentityServiceProvider.4joc7jl09rf6fmmmnqnvfohqo9.4bab76f8-d325-4501-9e13-1f98e21a8078.accessToken' => {
name: 'CognitoIdentityServiceProvider.4joc7jl09rf6fmmmnqnvfohqo9.4bab76f8-d325-4501-9e13-1f98e21a8078.accessToken',
value: '<value>'
},
'CognitoIdentityServiceProvider.4joc7jl09rf6fmmmnqnvfohqo9.4bab76f8-d325-4501-9e13-1f98e21a8078.idToken' => {
name: 'CognitoIdentityServiceProvider.4joc7jl09rf6fmmmnqnvfohqo9.4bab76f8-d325-4501-9e13-1f98e21a8078.idToken',
value: '<value>'
},
'CognitoIdentityServiceProvider.4joc7jl09rf6fmmmnqnvfohqo9.4bab76f8-d325-4501-9e13-1f98e21a8078.refreshToken' => {
name: 'CognitoIdentityServiceProvider.4joc7jl09rf6fmmmnqnvfohqo9.4bab76f8-d325-4501-9e13-1f98e21a8078.refreshToken',
value: '<value>'
},
'CognitoIdentityServiceProvider.4joc7jl09rf6fmmmnqnvfohqo9.4bab76f8-d325-4501-9e13-1f98e21a8078.signInDetails' => {
name: 'CognitoIdentityServiceProvider.4joc7jl09rf6fmmmnqnvfohqo9.4bab76f8-d325-4501-9e13-1f98e21a8078.signInDetails',
value: '{"loginId":"<email>","authFlowType":"USER_SRP_AUTH"}'
},
'CognitoIdentityServiceProvider.4joc7jl09rf6fmmmnqnvfohqo9.4bab76f8-d325-4501-9e13-1f98e21a8078.clockDrift' => {
name: 'CognitoIdentityServiceProvider.4joc7jl09rf6fmmmnqnvfohqo9.4bab76f8-d325-4501-9e13-1f98e21a8078.clockDrift',
value: '-914'
},
'CognitoIdentityServiceProvider.42p77ebvlqof523te23ah923us.LastAuthUser' => {
name: 'CognitoIdentityServiceProvider.42p77ebvlqof523te23ah923us.LastAuthUser',
value: '690a2dcf-fb1f-41e9-a726-21599dccb079'
},
'CognitoIdentityServiceProvider.42p77ebvlqof523te23ah923us.690a2dcf-fb1f-41e9-a726-21599dccb079.refreshToken' => {
name: 'CognitoIdentityServiceProvider.42p77ebvlqof523te23ah923us.690a2dcf-fb1f-41e9-a726-21599dccb079.refreshToken',
value: '<value>'
},
'CognitoIdentityServiceProvider.42p77ebvlqof523te23ah923us.690a2dcf-fb1f-41e9-a726-21599dccb079.signInDetails' => {
name: 'CognitoIdentityServiceProvider.42p77ebvlqof523te23ah923us.690a2dcf-fb1f-41e9-a726-21599dccb079.signInDetails',
value: '{"loginId":"[email protected]","authFlowType":"USER_SRP_AUTH"}'
},
'CognitoIdentityServiceProvider.42p77ebvlqof523te23ah923us.690a2dcf-fb1f-41e9-a726-21599dccb079.accessToken' => {
name: 'CognitoIdentityServiceProvider.42p77ebvlqof523te23ah923us.690a2dcf-fb1f-41e9-a726-21599dccb079.accessToken',
value: '<value>'
},
'CognitoIdentityServiceProvider.42p77ebvlqof523te23ah923us.690a2dcf-fb1f-41e9-a726-21599dccb079.idToken' => {
name: 'CognitoIdentityServiceProvider.42p77ebvlqof523te23ah923us.690a2dcf-fb1f-41e9-a726-21599dccb079.idToken',
value: '<value>'
},
'CognitoIdentityServiceProvider.42p77ebvlqof523te23ah923us.690a2dcf-fb1f-41e9-a726-21599dccb079.clockDrift' => {
name: 'CognitoIdentityServiceProvider.42p77ebvlqof523te23ah923us.690a2dcf-fb1f-41e9-a726-21599dccb079.clockDrift',
value: '-974'
},
Also, i tried manually logging the error by adding console.log statements to
node_modules/@aws-amplify/auth/dist/esm/providers/tokenProvider/TokenStore.mjs
async loadTokens() {
// TODO(v6): migration logic should be here
// Reading V5 tokens old format
try {
const authKeys = await this.getAuthKeys();
const accessTokenString = await this.getKeyValueStorage().getItem(
authKeys.accessToken,
);
// other code ...
return tokens;
} catch (err) {
console.error("Error loading tokens:", err);
return null;
}
and the result is the following error
Error loading tokens: NoSessionFoundException: Auth session was not found. Make sure to call signIn.
at async operation (src/amplify/serverside.ts:18:24)
at async getTokensServerside (src/amplify/serverside.ts:14:20)
at async Page (src/app/login/page.tsx:17:62)
16 | operation: async (contextSpec) => {
17 | console.log(await cookies());
> 18 | const session = await fetchAuthSession(contextSpec);
| ^
19 | return session;
20 | },
21 | }); {
underlyingError: undefined,
recoverySuggestion: undefined,
constructor: [class AuthError extends AmplifyError]
I feel like I've tried everything and nothing will make this work locally anymore. Although it's very wired that the exact same code is working perfectly fine in production.
aws-exports.js
No response
Manual configuration
config.ts
import { config } from "@/config";
import { ResourcesConfig } from "aws-amplify";
export const amplifyConfig: ResourcesConfig = {
Auth: {
Cognito: {
userPoolClientId: config.userPoolClientId,
userPoolId: config.userPoolId,
identityPoolId: config.identityPoolId,
allowGuestAccess: true,
passwordFormat: {
minLength: 8,
requireLowercase: true,
requireNumbers: true,
requireUppercase: true,
},
loginWith: {
email: true,
username: false,
},
},
},
};
these variables are set as following:
NEXT_PUBLIC_USER_POOL_ID="us-east-1_Tb7NcMxsy"
NEXT_PUBLIC_USER_POOL_CLIENT_ID="42p77ebvlqof523te23ah923us"
NEXT_PUBLIC_IDENTITY_POOL_ID="us-east-1:85d3dc65-7bcd-45ad-bcbf-80d09b8cc539"
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
Okay so after much more digging around timeouts, I added a patch this file to add a console log statement
dist/esm/utils/isValidCognitoToken.mjs
const isValidCognitoToken = async (input) => {
const { token, verifier } = input;
try {
console.log("Verifying Cognito token:", token);
await verifier.verify(token);
return true;
} catch (error) {
console.log("Error verifying Cognito token:", error);
// When `JwtExpiredError` is thrown, the token should have valid signature
// but expired. So, we can consider it as a valid token.
// Reference https://github.com/awslabs/aws-jwt-verify/blob/8d8f714d7281913ecd660147f5c30311479601c1/src/jwt-rsa.ts#L290-L301
if (error instanceof JwtExpiredError) {
return true;
}
// TODO (ashwinkumar6): surface invalid cognito token error to customer
// TODO: clear invalid tokens from Storage
return false;
}
};
export { isValidCognitoToken };
//# sourceMappingURL=isValidCognitoToken.mjs.map
And i finally found that i was getting the following timeout error while validating the token
Server Error verifying Cognito token: Error: Failed to fetch https://cognito-idp.us-east-1.amazonaws.com/us-east-1_Tb7NcMxsy/.well-known/jwks.json: Response time-out (after 1500 ms.)
at resolveErrorDev (react-server-dom-turbopack-client.browser.development.js:1838:46)
at getOutlinedModel (react-server-dom-turbopack-client.browser.development.js:1322:22)
at parseModelString (react-server-dom-turbopack-client.browser.development.js:1462:15)
at Array.<anonymous> (react-server-dom-turbopack-client.browser.development.js:2267:18)
at JSON.parse (<anonymous>)
at resolveConsoleEntry (react-server-dom-turbopack-client.browser.development.js:2102:28)
at processFullStringRow (react-server-dom-turbopack-client.browser.development.js:2243:11)
at processFullBinaryRow (react-server-dom-turbopack-client.browser.development.js:2206:7)
at progress (react-server-dom-turbopack-client.browser.development.js:2452:17)
Is there a way to increase this timeout?
Hi @qisaw, thanks for creating this issue. I will come back to it once I have more information.
Hi @qisaw,
currently, Amplify doesn't expose this timeout as a configurable option - it's hardcoded in the underlying aws-jwt-verify library. One option is to use patch-package to modify this timeout, but it's not the optimal long-term solution as you'd need to maintain the patch across dependency updates. Please let us know if you have any further questions.
Hi @soberm
Thanks for the info, I can do this for now, but I'd prefer not to in the long run.
Would this be on your roadmap anywhere in the future?
Thanks for the help.
Hey @qisaw, thanks for confirming that you could apply the workaround. It is currently in our backlog, but we don't have any timeline of when we would look at this feature request.