How to add JOI validator to firebase function as a middleware? I call firebase function like below:
exports.createUserAccount = region("europe-east1").https.onCall(createAccount); // createAccount is an function
in normal endpoints/routes in express i do something like this:
app.post("/app/some/endpoint", auth(), validator(), createAccount());
where my validator is an Joi middleware where I check that req.body is correct like a provided schema.
PS. I don't have an (req, res) in createAccount function, cause firebase return provided in this function an simple dto.
Thanks for any help
You can use JOI middlewares on Firebase by exposing an Express app via HTTP triggered functions and via Callable functions.
onRequest and onCall both takes a function that will return a Promise. Starting from here, you can create an Express application, register any middleware you want, then pass the Express app to the onCall.
The way to create the Express app is greatly documented here. Note that there is a big difference between onRequest and onCall: