#using bcrypt in edge worker

15 messages · Page 1 of 1 (latest)

solar arch
#

I think I can add this to my vite config:

#

ssr: {
noExternal: [
'bcrypt',
'jsonwebtoken’,
],
},

pliant tusk
#

what does it intend to do ?

solar arch
#

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

alpine dagger
solar arch
#

Stilll working on it

solar arch
#

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

brittle grove
#

using bcrypt in edge worker