-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
Next.js
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
None
Environment information
Hello, developers! I have been facing bug that prevent getting data for authenticated users in SSR for past months. After decided to debug this issue, I think I find where the problem is coming from. Here I am using Next 15 with Page Router and relied heavy on getServerSideProps. When trying to fetchAuthSession
in SSR, it keeps return undefined only in development. When deployed to production with SST, the app run normally without any issue.
Describe the bug
When I called fetchAuthSession in getServerSideProps,
then it returned undefined only in development,
but it is working in production.
Expected behavior
When I called fetchAuthSession in getServerSideProps,
then it should return session.
Reproduction steps
...
Code Snippet
{
"name": "web",
"version": "0.0.0",
"private": true,
"dependencies": {
"@aws-amplify/adapter-nextjs": "^1.4.0",
"aws-amplify": "^6.12.0",
"next": "15.1.6",
}
"devDependencies": {
"sst": "2.41.4",
"tailwindcss": "^4",
"tsconfig": "*"
}
}
Log output
// Put your logs below this line
aws-exports.js
No response
Manual configuration
import { ResourcesConfig } from 'aws-amplify'
const isBrowser =
typeof globalThis.window !== 'undefined' && globalThis.window.location.origin
let host
if (isBrowser) {
host = window.location.origin
} else if (process.env.NODE_ENV === 'production') {
host = `https://${process.env.NEXT_PUBLIC_DOMAIN_NAME}`
} else if (process.env.NODE_ENV === 'development') {
host = `http://localhost:3000`
}
const configure: ResourcesConfig = {
API: {
GraphQL: {
endpoint: process.env.NEXT_PUBLIC_GRAPHQL_APPSYNC_API_URL!,
apiKey: process.env.NEXT_PUBLIC_GRAPHQL_APPSYNC_API_KEY!,
region: process.env.NEXT_PUBLIC_REGION,
defaultAuthMode: 'apiKey'
}
},
Auth: {
Cognito: {
userPoolId: process.env.NEXT_PUBLIC_USER_POOL_ID!,
userPoolClientId: process.env.NEXT_PUBLIC_USER_POOL_WEB_CLIENT_ID!,
loginWith: {
oauth: {
domain:
process.env.NEXT_PUBLIC_DOMAIN_NAME === 'xxx'
? 'xxx'
: `auth-${process.env.NEXT_PUBLIC_DOMAIN_NAME}`,
responseType: 'code',
scopes: [
'email',
'openid',
'profile',
'aws.cognito.signin.user.admin'
],
redirectSignIn: [`${host}/sign-in/callback`],
redirectSignOut: [`${host}/sign-out`]
}
}
}
}
}
export { configure }
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

