How can I use an imported library

I imported the bcrypt library, but I can't use it
image
image

What is the way to use this library? thanks

Hi @Mary_Jimenz! We support importing most libraries, but not all unfortunately.

I did find a min.js URL for bcrypt (https://cdnjs.cloudflare.com/ajax/libs/bcryptjs/2.4.3/bcrypt.min.js), but haven't been able to get Retool to use bcrypt or any associated methods, which means it's likely just not supported.

nanoId seems to be working for me, if that's helpful at all! If not, would you mind sharing more about your use case so I can see if we have any workarounds for you?

Thanks for your answer, we need this library to encrypt a password and store it in a Mongo collection.

Got it! Would this library work for you?

https://cdn.jsdelivr.net/npm/browser-crypto@1.4.0/dist/browser-crypto.min.js

Add

Here's a function that I've gotten to work to encrypt plain text with that library. It accepts a plain text input (e.g. an unecrypted password) and a key that you'd like to use to encrypt:

function encrypt(plainText, key) {
const cipher = browserCrypto.createCipher('aes192', key)
let encrypted = cipher.update(plainText, 'utf8', 'hex')
encrypted += cipher.final('hex')
return `__IS_ENCRYPTED__(${encrypted})`
// or just return encrypted
}

return encrypt(textArea1.value, textInput1.value)