kinde-oss / kinde-auth-nextjs

Kinde NextJS SDK - authentication for server rendered apps
https://kinde.com/docs/developer-tools/nextjs-sdk/
MIT License
150 stars 20 forks source link

Cookies error in Next.js Edge #91

Closed Avililla closed 9 months ago

Avililla commented 11 months ago

Prerequisites

Describe the issue

When I use Edge functions with the last version of library, an error appears Error [TypeError]: Native module not found: cookie.

export const runtime = 'edge';
export async function POST(req:NextRequest){
    const {getUser} = getKindeServerSession()
    const user = await getUser()
}

This code you can see here doesnt works and generate the problem, but when you set this api route as no edge function it gives the error descriped

Library URL

https://github.com/kinde-oss/kinde-auth-nextjs

Library version

"@kinde-oss/kinde-auth-nextjs": "^2.0.4",

Operating system(s)

Windows

Operating system version(s)

Windows 11

Further environment details

No response

Reproducible test case URL

No response

Additional information

No response

peterphanouvong commented 11 months ago

@Avililla I merged a PR for it and will release in v2.0.5

Avililla commented 11 months ago

Okay thanks mate

peterphanouvong commented 11 months ago

@Avililla, should be up here: https://www.npmjs.com/package/@kinde-oss/kinde-auth-nextjs/v/2.0.5 - hopefully its all good for you now

Avililla commented 11 months ago

Im going to try it thanks😀

Avililla commented 11 months ago

Hello @peterphanouvong the problem persists.

 ⨯ node_modules/.pnpm/@kinde-oss+kinde-auth-nextjs@2.0.5_next@14.0.1_react-dom@18.2.0_react@18.2.0/node_modules/@kinde-oss/kinde-auth-nextjs/dist/server/index.js (1:592) @ require
 ⨯ Native module not found: cookie
null

There you have the problem, im also trying to figure out what causes this, until resolution im in 2.0.2 version. Thanks.

peterphanouvong commented 10 months ago

Hey @Avililla - I believe the cause was const cookies = require("cookies") in the sessionManager file. It should be fixed in 2.0.5 (latest)

peterphanouvong commented 10 months ago

I managed to reproduce - having another look at this now & reopening the issue

elmdecoste commented 10 months ago

I'm running into this same issue using the node runtime as well

peterphanouvong commented 10 months ago

Hey @elmdecoste @Avililla I have it working with v2.0.7 - let me know if there are any issues

DaveOrDead commented 9 months ago

Am going to close this one as appears to be resolved.