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

111
Vistas
Express.js API and Postgres. Make "username" unable to change for * days after it is changed

Hello guys I'm working on a "social Media" application, and today I made change username route. Everything works fine but I need to make username "unchangable" for * days after it is changed. Can someone tell me how to do it?

Code:

AuthRouter.post("/change-username", Authorize, async (req, res) => {
  const { username } = req.body
  try {

    if(!username) {
      return res.status(400).json("Please fill in all fields")
    }

    const previousUsername = await pool.query(
      "SELECT user_name FROM users WHERE user_id = $1",
      [req.user.id] 
    ) 

    const checkNewUsername = await pool.query("SELECT * FROM users WHERE user_name = $1", [
      previousUsername
    ])

    if (checkNewUsername.rows.length > 0) {
      return res.status(401).json("Email or Username is already in use")
    }

    await pool.query("UPDATE users SET user_name = $1 WHERE user_id = $2 RETURNING *", [
      username, req.user.id
    ])

    return res.status(200).json("Username changed")
  } catch (error) {
    console.error(error)
  }
})

Note: I'm not telling you to write my code but to tell me some ways how should I do it

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