What is the process for integrating a JOI validator with a Firebase function?

Is there a way to incorporate JOI validator into Firebase functions as middleware? When calling a Firebase function, it looks something like this:

exports.createUserAccount = region("europe-east1").https.onCall(createAccount); // createAccount is a function

In normal Express endpoints or routes, I typically do something like the following:

app.post("/app/some/endpoint", auth(), validator(), createAccount());

My validator is a JOI middleware where I verify that req.body follows a specified schema.

PS. My createAccount function does not include (req, res), as Firebase returns a simple DTO within this function.

Thank you for any assistance.

Answer №1

To integrate JOI middlewares with Firebase, you can utilize Express app through HTTP triggered functions and Callable functions.

Both onRequest and onCall require a function that returns a Promise. With this foundation, you can establish an Express application, incorporate any middleware of your choice, and then pass the Express app to onCall.

The process of creating the Express app is thoroughly documented here. It's essential to understand the distinction between onRequest and onCall:

  • onRequest exposes the complete Express app, allowing you to define routes and create a REST API;
  • onCall encapsulates your Express app as the SDK triggers it with a POST request. This means you need to handle only one request in your Express app, route it to the root path, and anticipate a POST request.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I check and add contacts on Telegram?

Assistance needed: I have 40,000 mobile numbers and I need to perform the following tasks: Verify if these numbers have a Telegram account Add these accounts to the contact list Can anyone provide advice on how to accomplish this? Perhaps with examples o ...

In ReactJS, organizing arrays within arrays for nesting purposes

Recently, I initiated a fresh project with React. I designed and brought in images by importing them: import Tip1 from "./img/Tips1.png"; import Tip2 from "./img/Tips2.png"; import Tip22 from "./img/Tips2-2.png"; ...

Disappearing Data Mystery in ngFor Array

In my Angular 6 component, I have created a form for adding new users using an HTML table: user-add.component.html [...] <tbody> <tr *ngFor="let value of data.pos; let i = index"> <td><input matInput [(ngModel)]="value.us ...

Exploring outside iframe data

My webpage includes an iframe A with a src attribute that links to a URL containing another embedded iframe B. I'm trying to figure out if it's possible to access the src of this nested iframe B. However, it appears that browser security measures ...

Increase the Speed of setInterval in JavaScript

I'm currently experimenting with gradually decreasing the interval at which a function is executed within a setInterval method. Below is a simplified example code snippet: var speed = 100; window.setInterval( speed -= 0.01 , speed); I suspect that ...

Dealing with Unexpected Timeout Errors and Memory Leaks in Express/Typescript Using Jest, Supertest, and TypeORM

Currently, I am in the process of writing unit tests for an express API. Each test suite initiates a fresh instance of an express server before running the tests. Individually, each test suite runs smoothly without any problems. However, when executed tog ...

Having trouble grasping the concept of Interfaces and dealing with FormGroup problems in Angular?

Apologies if my question is a duplicate, I have found several solutions for the same issue on Stack Overflow, but unfortunately, I struggle to understand them in technical terms. Problem 1 src/app/models/dataModel.ts:2:5 2 id: number; ~~ The exp ...

What are the steps for encoding a value using jquery serialize?

I attempted to encode all values using the following code: encodeURIComponent($("#customer_details").serialize()); Unfortunately, it did not produce the desired results. Is there a method to retrieve all elements on a form and individually encode each v ...

Grab all the text using Java Jsoup

I am having an issue with the code I have written. The doc.body.text() statement is not displaying the text content within the style and script tags. I examined the .text() function code and found that it searches for all instances of TextNode. Can someone ...

What is the best way to guide a user to a specific page based on the choice they made after submitting a form?

My form includes a list of 6 options where users can only select one. After submitting the form, I want to redirect them to a specific page based on their selection. For example, I have the following 3 options: Facebook Youtube Twitter If a user selects ...

Leveraging the power of LocalNotificationSchedule and Firebase Notification within a single React Native application

Can localNotificationSchedule and Firebase Remote Push Notification be used simultaneously in a React Native app? Utilizing the shared library on https://github.com/zo0r/react-native-push-notification indicates that the AndroidManifest.xml requires two sep ...

Having trouble adjusting the color on Material UI select in ReactJS?

Here is the code snippet I am working with: const useStyles = makeStyles({ select: { '&:before': { borderColor: 'white', }, '&:after': { borderColor: 'white&apos ...

Guide to incorporating a jade file into a node.js application after executing an Ajax request

While working on my node.js application, I encountered an issue with loading a new HTML file using Ajax on a button click. Despite everything else working perfectly, the new HTML file was not being loaded. This is how I am making the ajax call in my main. ...

NgrxStore - An initial item has been added twice to the array

Currently experimenting with ngrx store and manipulating elements within an array, such as deleting, fetching, and editing, works smoothly. However, a challenge arises when inserting an object into the array for the first time, duplicating the entry unless ...

Can the browser tabs automatically detect when a user logs out?

When I have multiple tabs open of the same website in a browser, I wonder how other windows can detect when a user has logged out. My development setup involves using Python/Django. The method I am currently implementing is: function user_checking(){ ...

Retrieve all information from a JSON array

Encountering a minor issue with a basic task. Here is the code snippet in question: JavaScript code Currently able to access the first object element, however, I require all the data objects. I suspect that a modification is needed in this particular cod ...

Creating a constructor that assigns values by using interfaces that are built upon the class

Looking at this interface/class example export interface MyErrorI { something: boolean; } export class MyError extends Error implements MyErrorI { public something = false; constructor(message: string, key: keyof MyErrorI ) { super(m ...

The Angular code is currently unable to retrieve the quiz ID

Hey there, I am encountering an issue with fetching the Qid from the server side. Interestingly enough, it works perfectly fine in Postman but not in Angular. The problem seems to be isolated to the Quiz ID retrieval, as other IDs like Category ID and Ques ...

When using Rspec and Capybara, utilizing jQuery to set focus on an element may not apply the `:focus` CSS as expected

I have implemented jump links for blind and keyboard users on my website, but I've hidden them off-screen visually. When these links gain focus, they are moved into the viewport. Trying to test this behavior using RSpec and Capybara has been unsucces ...

Issue with Saving Query Loop Results in Prisma MySQL with NextJS/ReactJS

I'm struggling with a Prisma query that is giving me grief. Despite my best efforts, I can't figure out why it's not functioning properly. The getImages() method below is intended to retrieve all the images associated with a product. Query ...