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

108
Views
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
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!