kinde-oss / kinde-auth-nextjs

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

kinde-auth-nextjs fails on edge runtime #56

Closed Thinkscape closed 1 year ago

Thinkscape commented 1 year ago

Prerequisites

Describe the issue

Unable to use the SDK with edge runtime as it crashes trying to import node crypto, probably from transient jwt-decode or crypto-js 🤷

import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";

export const runtime = "edge";

export default function Home() {
  const { getUser, isAuthenticated } = getKindeServerSession();
  const user = getUser();

  return <></>;
}
- error ./node_modules/.pnpm/@kinde-oss+kinde-auth-nextjs@1.8.16_react-dom@18.2.0_react@18.2.0/node_modules/@kinde-oss/kinde-auth-nextjs/dist/server/index.js:1:960
Module not found: Can't resolve 'crypto'

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

Library URL

https://github.com/kinde-oss/kinde-auth-react%E2%80%9D

Library version

1.8.16

Operating system(s)

Other Linux

Operating system version(s)

.

Further environment details

next 13.4.19

Reproducible test case URL

No response

Additional information

No response

DaveOrDead commented 1 year ago

Hey @Thinkscape thanks for raising, we'll get onto it asap

Thinkscape commented 1 year ago

This is a good replacement for JWT that works across all runtimes: https://www.npmjs.com/package/jose

DaveOrDead commented 1 year ago

Thanks for the tip @Thinkscape. Looks like the main issue is the Crypto lib. We've run some tests using the uncrypto package and that seems to resolve it. Should be a fix on the way soon

sagarregmi2056 commented 1 year ago

am new here i want to contribute to your project how can i?

DaveOrDead commented 1 year ago

@sagarregmi2056 great to hear! We're always open to contributions.

In terms of "how" we have our contributing guidelines which should be a good start.

Our repos have open issues you can jump onto (like this one you've found) so feel free to get stuck into them.

You can also join our Slack community and ask questions / see if there is anything the community is looking for

sagarregmi2056 commented 1 year ago

@DaveOrDead Thank you sir am from nepal searching for a place to level up my problem solving skills .Just now i have joined the slack community.Thanks for the guidence too.

DaveOrDead commented 1 year ago

@Thinkscape a PR has just gone in for this, could you confirm if upgrading to v1.8.23 resolves the edge runtime issue for you?

devarDilshad commented 6 months ago

@DaveOrDead greetings, I run into the same error saying that /dist/types/server is not exported from package I'm thrilled to use this and make your services into my default stack thanks for the efforts. versions: "@kinde-oss/kinde-auth-nextjs": "^2.2.5", "next": "14.2.3", "react": "^18", "react-dom": "^18"