英文:
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'] }
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论