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

440
Views
error TS2339: Property 'admin' does not exist on type 'User | undefined'

I have the following error Property 'admin' does not exist on type 'User | undefined', I'm trying to validate if the user is admin or not, can you help me to check where is the issue?

import { Request, Response, NextFunction } from "express";
import { getCustomRepository } from "typeorm";
import { UsersRepositories } from "../repositories/UsersRepositories";

export async function ensureAdmin(request: Request, response: Response, next: NextFunction) {

    const { user_id } = request;
    console.log(user_id);

    const usersRepositories = getCustomRepository(UsersRepositories);
    const { admin } = await usersRepositories.findOne(user_id);

    //verificar se o usuario é admin.
    if (admin) {
        return next();
    }

    return response.status(401).json({
        error: "Unauthorized!"
    })
}
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!