atinux / nuxt-auth-utils

Add Authentication to Nuxt applications with secured & sealed cookies sessions.
MIT License
973 stars 91 forks source link

Error: An instance of the Crypto API could not be located #242

Closed dvogelg4al closed 1 month ago

dvogelg4al commented 1 month ago

Version: 0.4.4

Simply installing the latest package and copying the Readme examples for Passkey integration (commenting out most of the database related code and leaving only console logs) immediately throws [nuxt] [request error] [unhandled] [500] An instance of the Crypto API could not be located upon attempting to register.

Not sure how to handle or debug. Happy to provide more details.

atinux commented 1 month ago

What OS are you using? Could you run npx nuxi info and paste it please?

dvogelg4al commented 1 month ago

npx nuxi info: `Nuxt project info: 09:23:50


Here is what I set up for the error to occur:

// server/api/webauthn/register.post.ts
export default defineWebAuthnRegisterEventHandler({
  async onSuccess(event, { credential, user }) {
    console.log("credential", credential);
    console.log("user", user);
  },
});

Plus the frontend example in the readme. Upon entering a username and clicking sign up, the crypto api error is immediately thrown.

Btw, another issue I have, when I install the packages for nuxt auth utils and webauthn, I first get another error: ROR [worker reload] [worker init] $fetch is not defined. I figured out this is due to a server utils file where I create a custom $fetch:

export const $serverApi = $fetch.create({
  baseURL: serverUrl,
  ....

The error only goes away if I explicity import $fetch from 'ofetch', which is otherwise not necessary when nuxt auth utils and the webauthn packages are not installed. (sorry if this should be a separate issue).

atinux commented 1 month ago

Could you please try with Node 20?

dvogelg4al commented 1 month ago

Could you please try with Node 20?

Just did and that appears to have fixed both issues. Thanks for the help! (And for making me upgrade to node 20 after i've had it on my to do list for quite a while...)