NickN
Convex Community12mo ago
6 replies
Nick

`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


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?
Was this page helpful?