Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
TypeORM (+express) .findOne promise isn't working

Hello I hope your all well,

I'm encountering one annoying issue when using typeORM. I can't use .then().catch(); right after 'userRepo.findOne'. But I'm almost certain that .findOne generates a Promise...

Could you please help me?

Thanks in advance for your help.

Find below my User Entity:

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[]>;
}

Find below my User Controller:

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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!