Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

268
Vistas
TypeORM (+express) .findOne promesa no funciona

Hola espero que estés bien,

Me encuentro con un problema molesto al usar typeORM. No puedo usar .then().catch(); justo después de 'userRepo.findOne'. Pero estoy casi seguro de que .findOne genera una Promesa...

¿Me podría ayudar?

Gracias de antemano por tu ayuda.

Encuentre debajo de mi entidad de usuario:

 import {Entity, PrimaryGeneratedColumn, Column, OneToMany} from "typeorm"; import { Post } from "./Post"; @Entity( {name : "Table_Personnes"} ) export class User { @PrimaryGeneratedColumn("uuid") Person_ID: number; @Column({ type: "varchar", length: 80}) Person_Email: string; @Column() Person_Login: string; @Column() Person_Password: string; @Column() Person_Picture: string; @OneToMany( (type) => Post, (Post) => Post.User) Table_Post: Promise<Post[]>; }

Encuentre debajo de mi controlador de usuario:

 import {getRepository} from "typeorm"; import {NextFunction, Request, Response} from "express"; //Import bcrypt import {bcrypt} from 'bcrypt' //Import token library import {jwt} from 'jsonwebtoken' //Import the entity model import {User} from "../entity/User"; import {Post} from "../entity/Post"; exports.login = (req, res, next) => { const userRepo = getRepository(User); userRepo.findOne({ Person_Email: req.body.user_email.toString().toLowerCase() }); .then((user) => { console.log("User that logged in: ", user); if (!user) { return res.status(401).json({ error: 'User not found !' }); } bcrypt.compare(req.body.password, user.Person_Password) .then(valid => { if (!valid) { return res.status(401).json({ error: 'wrong password !' }); } res.status(200).json({ userId: user._id, token: jwt.sign( { userId: user._id }, 'RANDOM_TOKEN_SECRET', { expiresIn: '24h' } ) }); }) .catch(error => res.status(500).json({ error })); }) .catch(error => res.status(500).json({ error })); };
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda