Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

58
Vistas
How do I refactor this code so it doesn't throw this error "Property 'patient' does not exist on type 'Request<ParamsDictionary>"?

Here's is my code. I'm trying to use passport authenticate to store the info of patients specific to the token created for each person.

router.get("/current", passport.authenticate("jwt", { session: false }), (req: Request, res: Response) => {
    res.json({
        id: req.patient.id,
        fullName: req.patient.fullName,
        age: req.patient.age,
        email: req.patient.email,
        phoneNumber: req.patient.phoneNumber,
        address: req.patient.address,
        medicalHistory: req.patient.medicalHistory,

    });
});

7 months ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I solved this problem by creating an interface that extends the Request type.

interface CustomRequest extends Request {
   patient?: any;
}

7 months ago · Juan Pablo Isaza Denunciar

0

You can use a type intersection like this:

req: Request & { patient: Record<string, any>}
7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos