shahradelahi / node-vault

🔐 Modern client for the HashiCorp's Vault API
https://www.npmjs.com/package/@litehex/node-vault
MIT License
247 stars 15 forks source link

NextJS Edge Runtime Support #61

Closed Charismara closed 1 week ago

Charismara commented 1 week ago

Describe the feature in detail (code, mocks, or screenshots encouraged)

Support for usage in NextJs Edge Runtime

What type of pull request would this be?

Other

Provide relevant links or additional information.

Usefull Docs: https://nextjs.org/docs/app/api-reference/edge

shahradelahi commented 1 week ago

The only thing that might not be compatible with the edge runtime of Next.js is undici, which is an HTTP client that is being used as the Node.js fetch API.

I'm not certain about how Next.js handles this, and I don't have any use cases. Please share details or error logs explaining what makes this library incompatible with the edge runtime.

Charismara commented 1 week ago

Use Case

We're storing OAuth2 Client Credentials in Vault. Those credentials are used by next-auth api endpoints to allow users to log themself in and by the next-auth middleware to provide and update the user session. Right now we're using the fetch method provided by nextjs to load those secrets but we would love to use this package.

Error

I run into this error when creating a new instance of Client on Edge Runtime:

⨯ Error: Cannot find module 'node:net': Unsupported external type Url for commonjs reference
    at <unknown> (file://C:\Users\<user>\IdeaProjects\frontend\.next\server\edge\chunks\ssr\bb6bd_undici_de3331._.js:8070:15)
    at Object.<anonymous> (file://C:\Users\<user>\IdeaProjects\frontend\.next\server\edge\chunks\ssr\bb6bd_undici_de3331._.js:8073:3)
    at [project]/node_modules/.pnpm/undici@6.19.8/node_modules/undici/lib/dispatcher/client.js [middleware] (ecmascript) (file://C:\Users\<user>\IdeaProjects\frontend\.next\server\edge\chunks\ssr\bb6bd_undici_de3331._.js:8525:3)
    at <unknown> (file://C:\Users\<user>\IdeaProjects\frontend\.next\server\edge\chunks\edge-wrapper_ae8a2c.js:535:27)
    at runModuleExecutionHooks (file://C:\Users\<user>\IdeaProjects\frontend\.next\server\edge\chunks\edge-wrapper_ae8a2c.js:577:9)
    at instantiateModule (file://C:\Users\<user>\IdeaProjects\frontend\.next\server\edge\chunks\edge-wrapper_ae8a2c.js:533:9)
    at getOrInstantiateModuleFromParent (file://C:\Users\<user>\IdeaProjects\frontend\.next\server\edge\chunks\edge-wrapper_ae8a2c.js:609:12)
    at commonJsRequire (file://C:\Users\<user>\IdeaProjects\frontend\.next\server\edge\chunks\edge-wrapper_ae8a2c.js:146:20)
    at Object.<anonymous> (file://C:\Users\<user>\IdeaProjects\frontend\.next\server\edge\chunks\ssr\bb6bd_undici_de3331._.js:21086:16)
    at [project]/node_modules/.pnpm/undici@6.19.8/node_modules/undici/index.js [middleware] (ecmascript) (file://C:\Users\<user>\IdeaProjects\frontend\.next\server\edge\chunks\ssr\bb6bd_undici_de3331._.js:21223:3)