Hello guys, happy to have discovered Rescript.
The hardest part of switching to Rescript, at least for me, is the lack of a clear how-to on how to bind. What is the best current practice to bind for example a Jsonwebtoken library. I thought at first I needed to use the @send because the verify and sign are methods.
Here’s what I came up with… Is this correct? I seriously doubt it:). Help will be appreciated.
module JsJwt = {
@module(“jsonwebtoken”)
external sign: ({…}, string) => string = “sign”
@module(“jsonwebtoken”) external verify: (string, string) => bool = “verify”
}
// 1) The idea is to do Jwt.sign({any object}, secret)
let token = JsJwt.sign({“foo”: “bar”}, “12345”)
Js.log(“The actual token generated” ++ token)
// 2) And obviously do Jwt.verify()
let isCorrect = JsJwt.verify(token, “12345”)
Js.log(isCorrect ? “true” : “false”)
I also put it on the playground playground