使用Vercel-Edge适配器在Qwik City中对密码进行哈希处理

huangapple go评论124阅读模式
英文:

Hashing Passwords with Vercel-Edge Adapter in Qwik City

问题

我有以下的代码,它使用argon2-browser包在服务器函数中对用户的密码进行哈希处理:

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' })

  ...
})

在使用Vercel-Edge适配器(使用npm run deploy)部署到Vercel时,我收到以下错误消息:

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.

有人知道如何解决这个问题吗,或者是否有另一个包可以让你在不出现此问题的情况下哈希密码?理想情况下,这不需要离开Vercel。TYA!

英文:

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!

答案1

得分: 1

我切换到了 bcrypt 并将以下内容添加到了我的 vite.config.ts 文件中:

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

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'],
        },

答案2

得分: 0

尝试设置外部路径吗?

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

英文:

Have you tried setting path to external?

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

huangapple
  • 本文由 发表于 2023年6月19日 09:33:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76503154.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定