nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
25.06k stars 3.54k forks source link

unstable_getServerSession() not working with nextjs13 #5759

Closed VaquarShaikh closed 2 years ago

VaquarShaikh commented 2 years ago

Environment

System: OS: Windows 10 10.0.22000 CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz Memory: 1.06 GB / 7.89 GB Binaries: Node: 19.0.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD npm: 8.5.3 - C:\Program Files\nodejs\npm.CMD Browsers: Chrome: 107.0.5304.88 Edge: Spartan (44.22000.120.0), Chromium (107.0.1418.35) Internet Explorer: 11.0.22000.120 npmPackages: next: 13.0.2 => 13.0.2 next-auth: ^4.16.4 => 4.16.4 react: 18.2.0 => 18.2.0

Reproduction URL

https://github.com/nextauthjs/next-auth/pull/5741

Describe the issue

Hi , I am trying to load session in nextjs13 , unstable_getserversession does not seem to work , I have followed the thread exactly and it gives me the following error

Unhandled Runtime Error Error: PrismaClient is unable to be run in the browser. In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues

This error comes after resolving a previous error

Cant find module v8

I installed v8 library using yarn add v8

after that I encountered prismaclient error.

How to reproduce

Below is the code snippet I am trying to run

` import { unstable_getServerSession } from "next-auth"; import { signIn, useSession } from "next-auth/react"; import Head from "next/head"; import Image from "next/image"; import styles from "../../styles/Home.module.css"; import { authOptions } from "./api/auth/[...nextauth]";

export default function Home() { const session = unstable_getServerSession(authOptions); return (

);

} `

Expected behavior

It should load session on server component .

VaquarShaikh commented 2 years ago

` import { unstable_getServerSession } from "next-auth"; import { signIn, useSession } from "next-auth/react"; import Head from "next/head"; import Image from "next/image"; import styles from "../../styles/Home.module.css"; import { authOptions } from "./api/auth/[...nextauth]";

export default function Home() { const session = unstable_getServerSession(authOptions); return (

);

}

` This is the snipppet i am using

marcostoduto commented 2 years ago

Happens to me too, news??

balazsorban44 commented 2 years ago

please provide a proper reproduction. are you using the edge runtime?

zenflow commented 2 years ago

This error comes after resolving a previous error Cant find module v8 I installed v8 library using yarn add v8

This is a real issue too, which I haven't gotten past because I don't want to install the "v8" package from npm which is clearly not the right "v8" module (and I don't know if it's safe): https://www.npmjs.com/package/v8

Here's the console log:

error - ./node_modules/openid-client/lib/helpers/deep_clone.js:1:33
Module not found: Can't resolve 'v8'

Import trace for requested module:
./node_modules/openid-client/lib/issuer.js
./node_modules/openid-client/lib/index.js
./node_modules/next-auth/core/lib/oauth/callback.js
./node_modules/next-auth/core/routes/callback.js
./node_modules/next-auth/core/routes/index.js
./node_modules/next-auth/core/index.js
./node_modules/next-auth/next/index.js
./node_modules/next-auth/index.js
./pages/_app.tsx

https://nextjs.org/docs/messages/module-not-found

The import trace points to this line in "openid-client": https://github.com/panva/node-openid-client/blob/35c6566625e0d1238b8ce14c0544b05c488197d3/lib/helpers/deep_clone.js#L1

I think the "v8" module it's trying to require is the native Node.js "v8" module: https://nodejs.org/docs/latest-v18.x/api/v8.html

I can require('v8') in the Node.js REPL just fine, so not sure why Next.js can't resolve the module.

Versions:

Not using Turbopack or any experimental Next.js features

balazsorban44 commented 2 years ago

Still, please add a reproduction. You likely use experimental-edge, or trying to use unstable_getServerSession in pages.

I'm converting this to a discussion, since this is not a NextAuth.js bug.