Environment
System:
OS: macOS 13.3.1
CPU: (8) arm64 Apple M2
Memory: 95.55 MB / 8.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 19.2.0 - ~/.nvm/versions/node/v19.2.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v19.2.0/bin/yarn
npm: 9.6.2 - ~/.nvm/versions/node/v19.2.0/bin/npm
Browsers:
Chrome: 112.0.5615.137
Safari: 16.4
Reproduction URL
https://github.com/ghoshnirmalya/the-fullstack-app
Describe the issue
The following code always returns null if I do console.log(session) when the code is present inside the Next.js API Routes within the app directory:
export async function GET() {
try {
const session = await getServerSession(authOptions);
..
}
You can find the relevant code here.
However, the following code from the React Server Components returns the correct data:
export default async function ProjectIndexPage() {
const session = await getServerSession(authOptions);
..
return (..)
}
The session in the above case is something like the following:
{
user: {
name: 'John Doe',
email: '[email protected]',
image: 'https://lh3.googleusercontent.com/john-doe',
id: '12345678910'
}
}
You can find the relevant code here.
How to reproduce
- Clone the repository:
- Install the necessary dependencies:
- Add the necessary env vars:
DATABASE_URL='mysql://database-url'
NEXT_PUBLIC_VERCEL_URL=127.0.0.1:3000
NEXTAUTH_SECRET=some-secret
NEXTAUTH_URL=http://127.0.0.1:3000
GOOGLE_CLIENT_ID=google-client-id
GOOGLE_CLIENT_SECRET=google-client-secret
- Generate the Prisma client:
npx prisma db push && npx prisma generate
- Run the development server:
Expected behavior
The session should return the correct object from the API Routes. The console.log(session) should return something like the following:
{
user: {
name: 'John Doe',
email: '[email protected]',
image: 'https://lh3.googleusercontent.com/john-doe',
id: '12345678910'
}
}
Environment
Reproduction URL
https://github.com/ghoshnirmalya/the-fullstack-app
Describe the issue
The following code always returns
nullif I doconsole.log(session)when the code is present inside the Next.js API Routes within the app directory:You can find the relevant code here.
However, the following code from the React Server Components returns the correct data:
The
sessionin the above case is something like the following:You can find the relevant code here.
How to reproduce
DATABASE_URL='mysql://database-url' NEXT_PUBLIC_VERCEL_URL=127.0.0.1:3000 NEXTAUTH_SECRET=some-secret NEXTAUTH_URL=http://127.0.0.1:3000 GOOGLE_CLIENT_ID=google-client-id GOOGLE_CLIENT_SECRET=google-client-secretnpx prisma db push && npx prisma generateExpected behavior
The
sessionshould return the correct object from the API Routes. Theconsole.log(session)should return something like the following: