Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

246
Visualizações
No overload matches this call.The last overload gave the following error. while writing firebase functions using Typescript

No overload matches this call.The last overload gave the following error. This is the error i get from the firebase functions

i wrote a code for the closed endpoints to privilege the routes, up to middleware everything is working fine but when i try to use that endpoint the error is coming.

Error Message:

No overload matches this call. The last overload gave the following error. Argument of type '(req: User, res: express.Response, next: express.NextFunction) => express.Response | Promise<void | express.Response>' is not assignable to parameter of type 'PathParams'.

This is my code


//controller.ts file
import { ProductModel } from "./model";
import * as express from "express";
import { endPoint } from "../../helpers/endpoint";
import { isAdmin } from "../../middlewares/middlewares";

const router = express.Router();

router
  .use(endPoint, isAdmin)
  .post("/admin/addProduct", (req: any, res: express.Response) => {
    const obj = new ProductModel(req.user);

    obj
      ._create_product(req.body)
      .then(() => {
        return res
          .status(201)
          .json({ message: "New Product created successfully" });
      })
      .catch((err) => {
        return res.status(404).json({ error: "Failed to create product", err });
      });
  });

export default router;

 //endpoint.ts file

import { admin, db } from "../config/admin";
import * as express from "express";

interface User extends express.Request{
  user:{
    email:string,
    uid:string
  }
}
export const endPoint = (
  req:User,
  res: express.Response,
  next: express.NextFunction
) => {
  if (!req.headers && !req.headers["authorization"]) {
    return res.status(404).json({ error: "UnAuthorised" });
  } else {
    const bearer: any = req.headers["authorization"];
    const token: any = bearer.split("Bearer ")[1];
    return admin
      .auth()
      .verifyIdToken(token)
      .then((decoded) => {
        console.log("decoded",decoded);
        req.user.uid=decoded.uid
        console.log("req.user",req.user.uid)
        return db
          .collection("USERS")
          .where("uid", "==", req.user)
          .limit(1)
          .get();
      })
      .then((userData) => {
        console.log(userData)
        req.user.email= userData.docs[0].data().email
        return next();
      })
      .catch((error) => {
        console.error(error);
        if (error.code === "auth/id-token-expired") {
          return res.status(401).json({
            message: `Token has expired please try again!!! with new Token`,
          });
        }
        return res.status(500).json({ message: `invalid token` });
      });
  }
};
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda