Squirble
Squirble4w ago

`use node` Convex Auth provider

I'm trying to write a convex auth provider that uses the node crypto package. Implementation: https://github.com/nickretallack/ranked-choice-convex/blob/92fbcb532aa40af85b3e613885e6bf0c694b87dd/convex/telegram/auth.ts#L9-L20 Used here https://github.com/nickretallack/ranked-choice-convex/blob/92fbcb532aa40af85b3e613885e6bf0c694b87dd/convex/auth.ts). Unfortunately, this causes convex to produce this error:
⠙ Bundling component schemas and implementations...
✘ [ERROR] Could not resolve "crypto"

node_modules/@grammyjs/validator/out/deps.node.js:4:25:
4 │ const crypto_1 = require("crypto");
╵ ~~~~~~~~

The package "crypto" wasn't found on the file system but is built into node. Are you trying to
bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
✖ It looks like you are using Node APIs from a file without the "use node" directive.
See https://docs.convex.dev/functions/runtimes#nodejs-runtime
⠙ Bundling component schemas and implementations...
✘ [ERROR] Could not resolve "crypto"

node_modules/@grammyjs/validator/out/deps.node.js:4:25:
4 │ const crypto_1 = require("crypto");
╵ ~~~~~~~~

The package "crypto" wasn't found on the file system but is built into node. Are you trying to
bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
✖ It looks like you are using Node APIs from a file without the "use node" directive.
See https://docs.convex.dev/functions/runtimes#nodejs-runtime
I know the solution to this is supposed to be annotating one of my files with "use node", but is the file I need somewhere inside of Convex Auth? Doesn't it make sense to have access to the node crypto package when writing a credentials authorization function?
6 Replies
Convex Bot
Convex Bot4w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
lee
lee3w ago
Existing auth providers use the web crypto library instead of the node one. Do you need behavior that's not supported by the built-in web crypto library?
Squirble
SquirbleOP3w ago
I'm using a library that uses node's crypto library. I suppose I could fork it.
Squirble
SquirbleOP3w ago
GitHub
GitHub - grammyjs/validator: Validation logic for Web Apps and logi...
Validation logic for Web Apps and login widgets. Contribute to grammyjs/validator development by creating an account on GitHub.
Squirble
SquirbleOP3w ago
Porting it to SubtleCrypto worked. Thanks!
sshader
sshader3w ago
For any future readers who need node and can't switch to web crypto, the auth provider itself can't have use node, but it can use ctx.runAction to call into other code that can be in a use node file (e.g. https://github.com/get-convex/convex-auth/blob/main/test/convex/otp/TwilioOTP.ts where the Twilio SDK seems to require Node)
GitHub
convex-auth/test/convex/otp/TwilioOTP.ts at main · get-convex/conve...
Library for built-in auth. Contribute to get-convex/convex-auth development by creating an account on GitHub.

Did you find this page helpful?