Bcrypt.res
@module("bcrypt") external hash: (string, int) => Promise.t<string> = "hash"
@moduel("bcrypt") external compare: (string, string) => Promise.t<bool> = "compare"
Bcrypt_test.res
let doit = async () => {
let password = "asdfasdfasdf"
let hash = await Bcrypt.hash(password, 10)
let authed = await Bcrypt.compare(password, hash)
Console.log2("authed", authed)
}
doit()->ignore
Bcrypt_test.bs.mjs
import * as Bcrypt from "bcrypt";
async function doit() {
var password = "asdfasdfasdf";
var hash = await Bcrypt.hash(password, 10);
var authed = await compare(password, hash);
console.log("authed", authed);
}
doit();
export {
doit ,
}
Error from running Bcrypt_test.bs.mjs
var authed = await compare(password, hash);
^
ReferenceError: compare is not defined
Compiles just fine. No warnings from VSCode. Did you spot the error? Took me about an hour to find it, and this isn’t the first time this happened. Next time maybe I’ll know what to look for.