#using bcrypt in edge worker
15 messages · Page 1 of 1 (latest)
what does it intend to do ?
My issue is that cloudflare pages throws an error because Bcrypt and jsonwebtoken throw an error because they do not work on edge
This worked but gave me a new error, something about module not being found
Do you know how to fix this
I really don’t want to use any other adapter
do you found a solution on buid and no external still have vite error no external
Stilll working on it
Finally got it!
(kind of)
I was not able to use bcrypt, so i made my own encrypting function using the crypto web api
export const HashText = async (
text: string,
requestEvent: RequestEventAction,
) => {
const hashUtf8 = new TextEncoder().encode(requestEvent.env.get('AUTH_SECRET'))
const hashBuffer = await crypto.subtle.digest('SHA-256', hashUtf8)
const textUtf8 = new TextEncoder().encode(text)
const alg = { name: 'AES-GCM', iv: hashUtf8 }
const encryptKey = await crypto.subtle.importKey(
'raw',
hashBuffer,
alg,
false,
['encrypt'],
)
return Array.from(
new Uint8Array(await crypto.subtle.encrypt(alg, encryptKey, textUtf8)),
)
.map((b) => b.toString(16).padStart(2, '0'))
.join('')
}```
No special Vite config needed
using bcrypt in edge worker