Reputation: 1
Normally we can't use bcrypt in edge functions. So when using bcrypt.js
const salt = bcrypt.genSaltSync(10);
const hash = bcrypt.hashSync(password, salt);
This produces an error
TypeError: import_bcryptjs.default.genSalt is not a function]
This error throws for everything (hash, hashsync, gensalt, gensaltsync)
I expected this to work normally but as I mentioned above it throws an error
TypeError: import_bcryptjs.default.genSalt is not a function]
I have installed
bun i @types/bcryptjs
and
bun i bcryptjs
so I don't know what's the problem and it's not a typo error.
So Then I tried @fntools/password a npm package which works well. @fntools/password npm package
well then is there something I'm missing in bcrypt.js? my tsconfig.js -->
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"strict": true,
},
}
my vercel.json -->
{
"rewrites": [
{
"source": "/api/(.*)",
"destination": "/api"
}
]
}
working code -->
import PasswordHasher from "@fntools/password";
const encrypt = new PasswordHasher(10);
export const HashPass = (password: string) => {
const hashedPassword = encrypt.hash(password);
console.log(hashedPassword);
return hashedPassword;
};
Upvotes: 0
Views: 523