Hashing Passwords with Vercel-Edge Adapter in Qwik City

356 Views Asked by At

I have the following code, which uses the argon2-browser package to hash the user's password in a server function:

export const authSignup = server$(async function (
  firstName: string,
  lastName: string,
  email: string,
  password: string,
  passwordConf: string,
  username: string,
) {

  ...

  const name = firstName.trim() + ' ' + lastName.trim()
  const hash = await argon2.hash({ pass: password, salt: 'somesalt' })

  ...
})

When deploying to Vercel using the Vercel-Edge adapter (using npm run deploy), I get the following error message:

RollupError: Cannot bundle Node.js built-in "path" imported from "node_modules/argon2-browser/dist/argon2.js". Consider disabling ssr.noExternal or remove the built-in dependency.

Does anyone know how to get around this, or if there is another package that lets you hash passwords without this issue? Ideally this would not require moving off of Vercel. TYA!

2

There are 2 best solutions below

2
On

Have you tried setting path to external?

vite: {
  ssr: { external: ['path'] }
}
0
On

I switched to bcrypt and added this to my vite.config.ts:

        resolve: {
            alias: {
                crypto: 'crypto-browserify',
                stream: 'stream-browserify',
                util: 'util-browser',
                events: 'events-browserify-mfsu',
            },
        },
        ssr: {
            external: ['bcrypt', 'stream', 'util', 'events'],
        },