Replies: 3 comments 2 replies
-
I've solved it for the moment by conditionally importing a polyfill: const webcrypto = typeof crypto !== 'undefined' ? crypto : new (await import("@peculiar/webcrypto")).Crypto |
Beta Was this translation helpful? Give feedback.
0 replies
-
This is what I ended up doing. import { nanoid } from "nanoid";
/**
* UIID composable
*
* @composable
*/
export default function useUIID() {
try {
// this should fail in node
self.crypto || window.crypto;
} catch (error) {
// inject crypto into the global node scope
global.crypto = global.crypto || require("crypto");
}
return { uuid: nanoid };
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
I got a similar problem with the Lucia library using
To fix it i've created a Nuxt plugin :
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to get an auth token in a way that's compatible with the Cloudflare Workers environment. CF workers uses the Web Crypto API. However, in development my API endpoints throw a 500 with
crypto is not defined
.I am using the
nitro: { preset: "cloudflare" }
configuration. This is an existing project that I'm porting to Nuxt, so I know the code is generally correct; it just doesn't seem to have access to the Web Crypto API in the Nitro dev server context. Ideas appreciated!Beta Was this translation helpful? Give feedback.
All reactions