Open siphosenkosindhlovu opened 3 weeks ago
I'm experiencing the same, regardless if using cookies from next/headers or request+response in middleware
Hi @siphosenkosindhlovu @austinjlaverty can you both confirm the following:
Amplify.configure(config, { ssr: true })
? Hi @siphosenkosindhlovu @austinjlaverty can you both confirm the following:
- Have you configured Amplify on your client-side with
Amplify.configure(config, { ssr: true })
?- After signing in an end user, have the auth tokens been written into browser cookie store?
Everything is configured on the front end. All cookies are present, I can long them in the Server Component. It even runs properly when deployed to AWS Amplify Hosting. But errors out when running locally witch fetchAuthSession(contextSpec)
returning an undefined
session.tokens
field. Client side fetches work correctly through
Hi @siphosenkosindhlovu @austinjlaverty can you both confirm the following:
- Have you configured Amplify on your client-side with
Amplify.configure(config, { ssr: true })
?- After signing in an end user, have the auth tokens been written into browser cookie store?
Yep, setting ssr: true, and cookies are in browser storage. Client amplify APIs work when retrieving a user from these stored values.
This is the final piece of my migration from v5 to v6. Everything else is functioning great
@austinjlaverty and @siphosenkosindhlovu, can you share what shape of your client side config looks like? Feel free to redact/remove any sensitive ID's or informaiton.
@austinjlaverty and @siphosenkosindhlovu, can you share what shape of your client side config looks like? Feel free to redact/remove any sensitive ID's or informaiton.
Here's what my amplifyconfiguration.json
looks like:
{
"aws_project_region": "us-east-1",
"aws_cloud_logic_custom": [
{
"name": "stripe",
"endpoint": "https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/canary",
"region": "us-east-1"
}
],
"aws_appsync_graphqlEndpoint": "https://xxxxxxxxxxxxxxxxx.appsync-api.us-east-1.amazonaws.com/graphql",
"aws_appsync_region": "us-east-1",
"aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",
"aws_appsync_apiKey": "xxxxxxxxxxxxxxxxxxxxx",
"aws_cognito_identity_pool_id": "us-east-1:xxxxxxxxxxxxxxxxxxxxxxx",
"aws_cognito_region": "us-east-1",
"aws_user_pools_id": "us-east-xxxxxxxxxxxxxx",
"aws_user_pools_web_client_id": "xxxxxxxxxxxxxxxxxx",
"oauth": {},
"aws_cognito_username_attributes": [
"EMAIL"
],
"aws_cognito_social_providers": [],
"aws_cognito_signup_attributes": [
"EMAIL"
],
"aws_cognito_mfa_configuration": "OFF",
"aws_cognito_mfa_types": [],
"aws_cognito_password_protection_settings": {
"passwordPolicyMinLength": 8,
"passwordPolicyCharacters": [
"REQUIRES_LOWERCASE",
"REQUIRES_UPPERCASE",
"REQUIRES_NUMBERS",
"REQUIRES_SYMBOLS"
]
},
"aws_cognito_verification_mechanisms": [
"EMAIL"
],
"aws_user_files_s3_bucket": "xxxxxxxxxxxxxxxxxxxxxxxx",
"aws_user_files_s3_bucket_region": "us-east-1"
}
@austinjlaverty and @siphosenkosindhlovu, can you share what shape of your client side config looks like? Feel free to redact/remove any sensitive ID's or informaiton.
Here is mine:
import { type ResourcesConfig } from "aws-amplify";
import { APP_URL } from "@/utils/env";
export const AMPLIFY_CONFIG: ResourcesConfig = {
Auth: {
Cognito: {
userPoolId: process.env.NEXT_PUBLIC_AMPLIFY_USER_POOL_ID!,
userPoolClientId:
process.env.NEXT_PUBLIC_AMPLIFY_USER_POOL_WEB_CLIENT_ID!,
loginWith: {
oauth: {
domain: process.env.NEXT_PUBLIC_AMPLIFY_OAUTH_DOMAIN!,
scopes: ["phone", "email", "profile", "openid"],
redirectSignIn: [`${APP_URL}/login/verify`],
redirectSignOut: [`${APP_URL}/`],
responseType: "code",
},
},
},
},
};
After some testing, it briefly worked when I'm behind a VPN (Cloudflare WARP in this instance) but stopped again.
@siphosenkosindhlovu want to circle back on this question from earlier. After signing in an end user, have the auth tokens been written into browser cookie store? Can you share the shape/values of the cookies in your cookie store?
@austinjlaverty, can you also share the shape/value of the cookies in your cookies store as well as clarify which API you're calling when you see this exception happening?
We're still trying to reproduce this on our side, but haven't been able to up to this point.
@siphosenkosindhlovu want to circle back on this question from earlier. After signing in an end user, have the auth tokens been written into browser cookie store? Can you share the shape/values of the cookies in your cookie store?
@austinjlaverty, can you also share the shape/value of the cookies in your cookies store as well as clarify which API you're calling when you see this exception happening?
We're still trying to reproduce this on our side, but haven't been able to up to this point.
My app is only using Auth. It interfaces with a separate services API layer built on AWS.
I'm attempting to getCurrentUser()
from aws-amplify/auth/server
within the operation callback:
import { cookies } from "next/headers";
import { Amplify } from "aws-amplify";
import {
fetchAuthSession,
getCurrentUser as getCurrentAmplifyUser,
} from "aws-amplify/auth/server";
import { createServerRunner } from "@aws-amplify/adapter-nextjs";
import { AMPLIFY_CONFIG } from "./config";
Amplify.configure(AMPLIFY_CONFIG, {
ssr: true,
});
export const { runWithAmplifyServerContext } = createServerRunner({
config: AMPLIFY_CONFIG,
});
export async function getCurrentUser() {
const user = await runWithAmplifyServerContext({
nextServerContext: { cookies },
operation: async (context) => {
const session = await fetchAuthSession(context);
console.log({ session, cookieStore: cookies() });
//if (!session.tokens) return;
const user = await getCurrentAmplifyUser(context);
console.log({ user });
return user;
},
});
if (!user) {
throw new Error("unauthenticated");
}
return user;
}
Upon successfully signing in from the client, cookies are present within the browser storage:
The same values are also present when logging the value of cookies()
from the server:
{
session: {
tokens: undefined,
credentials: undefined,
identityId: undefined,
userSub: undefined
},
cookieStore: RequestCookies {
_parsed: Map(10) {
'ajs_user_id' => [Object],
'ajs_anonymous_id' => [Object],
'CognitoIdentityServiceProvider.XXXXXXXXXXXXXXXXXXXXXXXXXX.LastAuthUser' => [Object],
'CognitoIdentityServiceProvider.XXXXXXXXXXXXXXXXXXXXXXXXXX.google_XXXXXXXXXXXXXXXXXXXXX.accessToken' => [Object],
'CognitoIdentityServiceProvider.XXXXXXXXXXXXXXXXXXXXXXXXXX.google_XXXXXXXXXXXXXXXXXXXXX.idToken' => [Object],
'CognitoIdentityServiceProvider.XXXXXXXXXXXXXXXXXXXXXXXXXX.google_XXXXXXXXXXXXXXXXXXXXX.refreshToken' => [Object],
'CognitoIdentityServiceProvider.XXXXXXXXXXXXXXXXXXXXXXXXXX.google_XXXXXXXXXXXXXXXXXXXXX.clockDrift' => [Object],
},
}
}
As a result, everything on the server (components, route handlers, middleware using request+response) all fail to retrieve the authenticated state. However, once the client initializes and invokes getCurrentUser()
from aws-amplify/auth
it successfully retrieves the logged in user, and the UI reflects this.
My setup is currently working locally and in production using v5.
Locally I'm based in SEA, but the AWS project is us-east-1. I have no idea if that helps or might influence any sort of edge case.
@siphosenkosindhlovu want to circle back on this question from earlier. After signing in an end user, have the auth tokens been written into browser cookie store? Can you share the shape/values of the cookies in your cookie store?
@austinjlaverty, can you also share the shape/value of the cookies in your cookies store as well as clarify which API you're calling when you see this exception happening?
We're still trying to reproduce this on our side, but haven't been able to up to this point.
Yep, they're being written to the browser store. When I use Amplify auth client side, it correctly shows as authenticated, but doesn't for SSR like for @austinjlaverty.
Here's what's logged from the server:
{
session: {
tokens: undefined,
credentials: {
accessKeyId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
secretAccessKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
sessionToken: 'IQoJb3JpZ2luX2VjECgaCXVzLWVhc3QtMSJHMEUCIQDyo9FUB9zOMoZWkdGxOImS1CXC5y70hF/v1YD3/8AXMgIgJNXExtQwZVgtpk17v0JCpjojWmrlwFcecykZ1Gv2jFsq0gUIof//////////ARAEGgw0MDUwOTQ1OTIwNzgiDOZOrKKSwmGFZNJYviqmBawH0IO5k9afRoU7g6cFY1Flbzl3dbB3fNIddHGj3aCHMwG/ptBG+4kmEa0x6dvab1iWaePeJgjcHCl3XKDdHgoT9MboVvvJIYBtRKMydLvixKbeVB0uea3MT38bhKQFYnsUXf1a0CcNexJnQwYi9di6CkScW74p1+2CHZxOKqToWD0GmHf8VvoFcOortgZFfcabMsPOd3PMVvd1IRV5MCJQvx/HmvES9yejOi8KC7fUlbiCpdA9lBzEy3MhN7KKg45H6lggl4ljn8boJZUx12iPuEk3DEp3jhyuQC/5Vnfmr8ogRgNRtqct/OcZhb6PuFD9IuuIvf/x13goMpkKBM/U508dIH+SbubUdcDJR37p0dYwno8IatGDKtDTZHoIUs6UllmFmEnrmh+wv6eOrsYafKNYFs5tHGYiJvRxGWi0n3AAixsO09naB9KCMACXhoXgT4Osxre2Z8Pka0P7dmwjLNsiLRpQQAGL34hdxWhi39dT1kkZdjXnwRs44AAIP+Wj4JscIgbC/bAyYY5NQDQQIwLFKF4zaj0ucMNO3R0QeLj0AjFcqpyY4BMG0bugZTM7S0rGfidHmmSppUG5Yo8xm36D1ifK/mSYJLoh5cMtIxKnPkCeBceJDEU/04KX1ukaIkNLd0/5IzEKbvgMmym/odrdT3hCu1JIEEjn4QPLEYBqYeFoo1l0NwpJz2YsXpQifZbTy06XLShRbUQ3Ct7uQxaodOGphMiR86qJAQDTG+OK9vLh+J/z9MLb8Qr8T9duR8a63U6WG5mzuJIeJiZJCkU9SkhzsGpA0bCwndlqfufXHLe9MwxNC2xLFLXFevIvaTcMIC4RrjsM5wK5timN1h70LDw3DfnwSThdAQFgPjh+7iqAg+G73Mg3NzqU8CyLqS3N4TCNkZK5BjrdAuGR7mCDDIytlSPL8U2HVmfzHDnl29uQkHzl+plM79/X6DlCXBiHxMibOIGc4awCNeP5WMCdGgxh/hDl7qM5RQXEqApenmCHyZcNBQ0vxiZ/L6dkjbLFpP0mrwIEZhpPU+xpakniYN9v/g3yv1/00Ng6D0ZAsff/jE9FNRL8CjjNFz6bXSN+RIC2DHpyQykqHK/aAT7RMHwwR8G0CUcyJp4qYR0YmBcTbGicCSNI8MsRmF4zEIjhoGyPZNrUg3lOZEhE4PayQ8mfz4n0xhN692euDQm/f7w7rfDSId223481bTn6gNWJGYW8ZNemxNx0NqjiCGP0JX7/8MefTAuPsrxCyYDpuyQKPZhCF8xCaCgdxZgg3fAh+u0Yo2wTmk0FSzGwHqq9EANPAKUCuQGKNBkI5BZSGGaOVOiynsBkCO4/OrAA+QXq6j13wUL20aFhALOb/V4EWS7gD2ck/vQ=',
expiration: 2024-11-01T08:51:41.000Z
},
identityId: 'us-east-1:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
userSub: undefined
},
cookies: f {
_parsed: Map(7) {
'activeProfile' => [Object],
'CognitoIdentityServiceProvider.xxxxxxxxxxxxxxxxxxxxxxxxxx.LastAuthUser' => [Object],
'CognitoIdentityServiceProvider.xxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.accessToken' => [Object],
'CognitoIdentityServiceProvider.xxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.idToken' => [Object],
'CognitoIdentityServiceProvider.xxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.refreshToken' => [Object],
'CognitoIdentityServiceProvider.xxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.signInDetails' => [Object],
'CognitoIdentityServiceProvider.xxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.clockDrift' => [Object]
},
_headers: Headers {}
}
}
And from the browser console:
It's only working when deployed to AWS Amplify.
@austinjlaverty and @siphosenkosindhlovu, greatly appreciate the detailed responses and follow up here. While we work on reproducing the issue on our side, are either of you able to provide a public, minimal sample repo or possibly invite to a private repo where this is happening?
@austinjlaverty, is your app also only experiencing this locally (but not when deployed)?
@austinjlaverty and @siphosenkosindhlovu, greatly appreciate the detailed responses and follow up here. While we work on reproducing the issue on our side, are either of you able to provide a public, minimal sample repo or possibly invite to a private repo where this is happening?
Hi, added you to a private. It's a barebones setup with a CSR and SSR component, CSR works but SSR errors out. Not sure if its possible to get more detailed logs to see if it's a network issue.
For what it's worth, my auth on Next.js 15 began failing after upgrading to amplify 6.8.0
. I began to get the error Auth UserPool not configured
. Had to revert back to 6.6.7
.
For what it's worth, my auth on Next.js 15 began failing after upgrading to amplify
6.8.0
. I began to get the errorAuth UserPool not configured
. Had to revert back to6.6.7
.
Next.js 15 is not supported by amplify at the moment if im not mistaken
@oznekenzo and @e-simpson, that is correct. NextJS 15 is not supported at this point. You can follow #13924 for updates on when it is fully supported on our side!
@cwomack tried running the demo app in WSL and it gives a network error in RSCs, but client side APIs still work.
Exact same code but this is the error:
{
e: AmplifyError [NetworkError]: A network error has occurred.
at fetchTransferHandler (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/handlers/fetch.mjs:31:19)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async retryMiddleware (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/middleware/retry/middleware.mjs:32:28)
at async userAgentMiddleware (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/middleware/userAgent/middleware.mjs:24:30)
at async eval (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/internal/composeServiceApi.mjs:20:26)
at async generateIdentityId (webpack-internal:///(rsc)/./node_modules/@aws-amplify/auth/dist/esm/providers/cognito/credentialsProvider/IdentityIdProvider.mjs:74:6)
at async cognitoIdentityIdProvider (webpack-internal:///(rsc)/./node_modules/@aws-amplify/auth/dist/esm/providers/cognito/credentialsProvider/IdentityIdProvider.mjs:58:21)
at async CognitoAWSCredentialsAndIdentityIdProvider.getCredentialsAndIdentityId (webpack-internal:///(rsc)/./node_modules/@aws-amplify/auth/dist/esm/providers/cognito/credentialsProvider/credentialsProvider.mjs:56:28)
at async AuthClass.fetchAuthSession (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/singleton/Auth/index.mjs:53:17)
at async operation (webpack-internal:///(rsc)/./app/on-ssr.tsx:33:33)
at async runWithAmplifyServerContext (webpack-internal:///(rsc)/./node_modules/aws-amplify/dist/esm/adapter-core/runWithAmplifyServerContext.mjs:25:24)
at async OnSSR (webpack-internal:///(rsc)/./app/on-ssr.tsx:27:25) {
underlyingError: TypeError: fetch failed
at node:internal/deps/undici/undici:13392:13
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async fetchTransferHandler (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/handlers/fetch.mjs:20:16)
at async retryMiddleware (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/middleware/retry/middleware.mjs:32:28)
at async userAgentMiddleware (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/middleware/userAgent/middleware.mjs:24:30)
at async eval (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/internal/composeServiceApi.mjs:20:26)
at async generateIdentityId (webpack-internal:///(rsc)/./node_modules/@aws-amplify/auth/dist/esm/providers/cognito/credentialsProvider/IdentityIdProvider.mjs:74:6)
at async cognitoIdentityIdProvider (webpack-internal:///(rsc)/./node_modules/@aws-amplify/auth/dist/esm/providers/cognito/credentialsProvider/IdentityIdProvider.mjs:58:21)
at async CognitoAWSCredentialsAndIdentityIdProvider.getCredentialsAndIdentityId (webpack-internal:///(rsc)/./node_modules/@aws-amplify/auth/dist/esm/providers/cognito/credentialsProvider/credentialsProvider.mjs:56:28)
at async AuthClass.fetchAuthSession (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/singleton/Auth/index.mjs:53:17)
at async operation (webpack-internal:///(rsc)/./app/on-ssr.tsx:33:33)
at async runWithAmplifyServerContext (webpack-internal:///(rsc)/./node_modules/aws-amplify/dist/esm/adapter-core/runWithAmplifyServerContext.mjs:25:24)
at async OnSSR (webpack-internal:///(rsc)/./app/on-ssr.tsx:27:25) {
[cause]: [AggregateError]
},
recoverySuggestion: undefined,
constructor: [class AmplifyError extends Error]
}
}
@cwomack tried running the demo app in WSL and it gives a network error in RSCs, but client side APIs still work.
Exact same code but this is the error:
{ e: AmplifyError [NetworkError]: A network error has occurred. at fetchTransferHandler (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/handlers/fetch.mjs:31:19) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async retryMiddleware (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/middleware/retry/middleware.mjs:32:28) at async userAgentMiddleware (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/middleware/userAgent/middleware.mjs:24:30) at async eval (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/internal/composeServiceApi.mjs:20:26) at async generateIdentityId (webpack-internal:///(rsc)/./node_modules/@aws-amplify/auth/dist/esm/providers/cognito/credentialsProvider/IdentityIdProvider.mjs:74:6) at async cognitoIdentityIdProvider (webpack-internal:///(rsc)/./node_modules/@aws-amplify/auth/dist/esm/providers/cognito/credentialsProvider/IdentityIdProvider.mjs:58:21) at async CognitoAWSCredentialsAndIdentityIdProvider.getCredentialsAndIdentityId (webpack-internal:///(rsc)/./node_modules/@aws-amplify/auth/dist/esm/providers/cognito/credentialsProvider/credentialsProvider.mjs:56:28) at async AuthClass.fetchAuthSession (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/singleton/Auth/index.mjs:53:17) at async operation (webpack-internal:///(rsc)/./app/on-ssr.tsx:33:33) at async runWithAmplifyServerContext (webpack-internal:///(rsc)/./node_modules/aws-amplify/dist/esm/adapter-core/runWithAmplifyServerContext.mjs:25:24) at async OnSSR (webpack-internal:///(rsc)/./app/on-ssr.tsx:27:25) { underlyingError: TypeError: fetch failed at node:internal/deps/undici/undici:13392:13 at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async fetchTransferHandler (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/handlers/fetch.mjs:20:16) at async retryMiddleware (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/middleware/retry/middleware.mjs:32:28) at async userAgentMiddleware (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/middleware/userAgent/middleware.mjs:24:30) at async eval (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/clients/internal/composeServiceApi.mjs:20:26) at async generateIdentityId (webpack-internal:///(rsc)/./node_modules/@aws-amplify/auth/dist/esm/providers/cognito/credentialsProvider/IdentityIdProvider.mjs:74:6) at async cognitoIdentityIdProvider (webpack-internal:///(rsc)/./node_modules/@aws-amplify/auth/dist/esm/providers/cognito/credentialsProvider/IdentityIdProvider.mjs:58:21) at async CognitoAWSCredentialsAndIdentityIdProvider.getCredentialsAndIdentityId (webpack-internal:///(rsc)/./node_modules/@aws-amplify/auth/dist/esm/providers/cognito/credentialsProvider/credentialsProvider.mjs:56:28) at async AuthClass.fetchAuthSession (webpack-internal:///(rsc)/./node_modules/@aws-amplify/core/dist/esm/singleton/Auth/index.mjs:53:17) at async operation (webpack-internal:///(rsc)/./app/on-ssr.tsx:33:33) at async runWithAmplifyServerContext (webpack-internal:///(rsc)/./node_modules/aws-amplify/dist/esm/adapter-core/runWithAmplifyServerContext.mjs:25:24) at async OnSSR (webpack-internal:///(rsc)/./app/on-ssr.tsx:27:25) { [cause]: [AggregateError] }, recoverySuggestion: undefined, constructor: [class AmplifyError extends Error] } }
But it works in Docker
@siphosenkosindhlovu @austinjlaverty I have been trying to reproduce the issue you are seeing , I have no success so far. I can push my barebone nextJS app and give the link to show u post login, i can see the tokens
& userSub
post login.
My repo link - https://github.com/ashika112/next-auth-gen2
Can you provide me with what customization are you both doing in addition to what is here to server side? that you think might be worth noting?
@siphosenkosindhlovu @austinjlaverty do u both see any network error before tokens
& userSub
becomes undefined
? or this is happening from beginning.?
If you're using the Next.js App Router, you can create a client component to configure Amplify and import it into your root layout.
ConfigureAmplifyClientSide.js:
'use client';
import { Amplify } from 'aws-amplify'; import config from '../amplifyconfiguration.json';
Amplify.configure(config, { ssr: true });
export default function ConfigureAmplifyClientSide() { return null; }
then in the root layout
import HeaderNav from "../components/HeaderUI/HeaderNav";
import Sidebar from "../components/Sidebar";
import Providers from "../provides";
import { GetAuthCurrentUserServer } from "@/utils/authentication";
import ConfigureAmplifyClientSide from "../ConfigureAmplifyClientSide";
const UserLayout = async ({ children }) => {
const session = await GetAuthCurrentUserServer();
console.log("CLIENT SESSION FROM LAYOUT", session);
return (
<Providers>
<ConfigureAmplifyClientSide />
<main className="flex">
<Sidebar />
<main className="w-full">
<HeaderNav session={session} />
{children}
</main>
</main>
</Providers>
);
}
export default UserLayout;
I hope it work on you as well 🚀🙂
@siphosenkosindhlovu @austinjlaverty do u both see any network error before
tokens
&userSub
becomesundefined
? or this is happening from beginning.?
I get the errors after running fetchAuthSession()
which returns an object with missing tokens
and userSub
and before getCurrentUser()
, which I'm guessing failes because there is no user in the session.
Update: No longer getting a network error but the same auth error on Ubuntu WSL. And again, everything works with Docker on the same computer, I guess I'll work that way for now.
@siphosenkosindhlovu, thanks for following up. Can you see if upgrading to the latest version of Amplify (currently v6.8.2) to see if the issue is resolved? That should resolve any issues that would be the result of a network error, but I'm curious to see if the Auth errors persist when upgrading as well.
If it's working in Docker, but not WSL, it may be something tied to support from the WSL side (rather than Amplify).
@cwomack updated to the latest version of Amplify and it's still the same. Doesn't work on native Windows and WSL.
@siphosenkosindhlovu the auth error will happen if tokens & userSub is undefined. You want to trace the cause for that. I dont think it is happening directly because of Amplify. Can you check what is happening the storage throughout the flow?
@cwomack @ashika112 tried on another PC connected to the same network and I'm getting the same errors. I can see the cookies when I console log them, but fetchAuthSession always returns returns undefined tokens. Not sure how to trace the problem further than that.
@siphosenkosindhlovu, do you have any type of global install on the WSL that could be using a different version of Next.JS? The stack trace shows the following:
underlyingError: TypeError: fetch failed
at node:internal/deps/undici/undici:13392:13
This looks like it could be related to the following from the Vercel repo - https://github.com/vercel/next.js/issues/48744
@cwomack nope. I don't have any global installs on WSL except for npm itself and corepack
@siphosenkosindhlovu, thanks for confirming. The more we look into this, the more I'm curious if you see any similar behavior to what the intended fix was from the Next.js team as seen in this PR where they needed to unset the header if the content-length
= 0.
Can you inspect your network requests in the WSL environment to see what the content-length
is when this issue happens?
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
Amplify CLI
Environment information
Describe the bug
Cannot use Amplify server api categories from NextJS server components on local computer, but works on deployment.
This code:
Throws this errror:
The session object undefined
tokens
anduserSub
fields event though the token is correctly set in the client and viewable on the server.Important to note that everything works normally in client components.
Expected behavior
getCurrentUser()
to return the credentials of the currently authenticated user.Reproduction steps
getCurrentUser()
api category.Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
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