logto-io / js

🤓 Logto JS SDKs.
https://docs.logto.io/quick-starts/
MIT License
56 stars 38 forks source link

bug: crypto is not defined #784

Open TheMikeyRoss opened 1 month ago

TheMikeyRoss commented 1 month ago

Describe the bug

I followed the express.js tutorial and when I try to make a call to /logto/sign-in I get the following error

[1] const generateRandomString = (length = 64) => jsBase64.fromUint8Array(crypto.getRandomValues(new Uint8Array(length)), true);
[1]                                                                       ^
[1]
[1] ReferenceError: crypto is not defined

How to reproduce?

  1. Create a express backend
  2. Follow the express.js tutorial
  3. See the same error as above

Context

TheMikeyRoss commented 1 month ago

it's coming specifically from handleAuthRoutes

wangsijie commented 1 month ago

What is your environment, it is normal Node.js or other serverless platforms.

TheMikeyRoss commented 1 month ago

Logto is hosted in a Ubuntu 24 VPS and I'm trying to send api calls to it from a localhost in my local machine using windows 10. (regular node.js 18.x env)

wangsijie commented 1 month ago

Is this error happend in application or Logto itself?

TheMikeyRoss commented 1 month ago

in my node application in my localmachine in localhost (express.js)

wangsijie commented 1 month ago

If this error happend in SDK runtime, then could you please check the runtime of you Express.js app and see if "crypto" is available, or you can provide a repo that reproduces this error and I'll take a look.

TheMikeyRoss commented 1 month ago

Yes I have crypto installed and it's listed in my package.json

wangsijie commented 1 month ago

Usually you don't need to install "crypto" manually.

TheMikeyRoss commented 1 month ago

honestly it was already installed in my project before I started using logto

wangsijie commented 1 month ago

Please provide a minimal project that can reproduce the issue. This will help me better understand and assist you with your problem, for now, there is no enough context.

TheMikeyRoss commented 1 month ago

The project im using it it is a huge monorepo with 14 workspaces in it. I will try to put together a minimal reproduction

alaa-eddine commented 2 days ago

I'm encountering the same issue and it's coming from this file : node_modules\@logto\express\node_modules\@logto\node\lib\edge\generators.js

and it seems that for @logto/express package is not using the right version of @logto/node

here is what I see in generator.js , it's actually referring to crypto without importing it

image