почему-то когда я логинюсь за одного пользователя в своем сайте {"id":18,"name":"govno123","genre":"Rock","instrument":"","password":"1111","role":"Band","city":"Москва","login":"govno123@gmail.com","thumbnail":"musician_18_kHx5I5oM7mo.jpg","region":""}]} то попадаю на {"id":2,"name":"Aerosmith111114446","genre":"Electronic","password":"1111","location":"EnglandDdDDDDDDD","thumbnail":"musician_2_jX7hQvfoT2g (2).jpg","bio":"","soundcloud":"https://soundcloud.com/ty-segall-official/my-ladys-on-fire?si=55e4a9622a824ddeb3e725dfa2c41d1d&utm_source=clipboard&utm_medium=text&utm_campaign=social_sharing","soundcloud1":"https://soundcloud.com/ty-segall-official/my-ladys-on-fire?si=55e4a9622a824ddeb3e725dfa2c41d1d&utm_source=clipboard&utm_medium=text&utm_campaign=social_sharing","city":"","role":"Band"}

вот мой код:

const express = require("express");
const fs = require("fs");
const session = require("express-session");
const fileUpload = require("express-fileupload");
const app = express();
const fuzzball = require("fuzzball");
const mysql = require('mysql');

const connection = mysql.createConnection({
  host: 'localhost',
  user: 'music', // замените на свой логин
  password: 'password', // замените на свой пароль
  database: 'music' // замените на свою базу данных
});

connection.connect((err) => {
  if (err) {
    console.error('Ошибка подключения к базе данных: ', err);
  } else {
    console.log('Подключение к базе данных успешно');
  }
});

app.set("view engine", "ejs");
app.use(express.static("public"));

app.use(express.urlencoded({ extended: true }));
app.use(fileUpload());
app.use(session({
  secret: "mysecretkey",
  resave: false,
  saveUninitialized: false
}));






const citiesAndRegions = JSON.parse(fs.readFileSync("./db/russia.json", "utf8"));


//const predefinedGenres = ['Rock', 'Pop', 'Jazz', 'Hip Hop', 'Electronic', 'Blues'];

function getLastNRegisteredMusicians(N) {
  const data = fs.readFileSync("./db/musicians.json");
  const musicians = JSON.parse(data);

  return musicians.musicians.slice(-3);
}

function getMusicianById(id) {
  const data = fs.readFileSync("./db/musicians.json");
  const musicians = JSON.parse(data);

  return musicians.musicians.find(musician => musician.id === id);
}

function requireLogin(req, res, next) {
  if (req.session.musicianId) {
    next();
  } else {
    res.redirect("/login");
  }
}

function search(query = '', role = '', city = '', genre = '') {
  const data = fs.readFileSync('./db/musicians.json');
  
  const musicians = JSON.parse(data).musicians.map(musician => {
    return {
      name: musician.name,
      genre: musician.genre,
      originalName: musician.name,
      profileLink: `/profile/${musician.id}`,
      thumbnail: musician.thumbnail,
      soundcloud: musician.soundcloud,
      role: musician.role,
	  city: musician.city
      
    };
  });

  let results = [];

  if (query || role || city || genre) {
    const lowerQuery = query.toLowerCase();
    results = musicians.filter(musician => {
      const nameScore = musician.name.toLowerCase().startsWith(lowerQuery) ? 2 : musician.name.toLowerCase().includes(lowerQuery) ? 1 : 0;
      const genreScore = musician.genre.toLowerCase().startsWith(lowerQuery) ? 2 : musician.genre.toLowerCase().includes(lowerQuery) ? 1 : 0;
      
     return (
    nameScore + genreScore > 0 &&
    (role === "" || musician.role === role) &&
	(city === "" || (musician.city && musician.city.toLowerCase().trim() === city.toLowerCase().trim())) &&
    (genre === "" || musician.genre.toLowerCase() === genre.toLowerCase())
  );

    }).sort((a, b) => {
      const aNameScore = a.name.toLowerCase().startsWith(lowerQuery) ? 2 : a.name.toLowerCase().includes(lowerQuery) ? 1 : 0;
      const bNameScore = b.name.toLowerCase().startsWith(lowerQuery) ? 2 : b.name.toLowerCase().includes(lowerQuery) ? 1 : 0;
      const aGenreScore = a.genre.toLowerCase().startsWith(lowerQuery) ? 2 : a.genre.toLowerCase().includes(lowerQuery) ? 1 : 0;
      const bGenreScore = b.genre.toLowerCase().startsWith(lowerQuery) ? 2 : b.genre.toLowerCase().includes(lowerQuery) ? 1 : 0;

      // Sort by name score, then genre score, then location score (descending)
      if (aNameScore + aGenreScore + a.location < bNameScore + bGenreScore + b.location) {
        return 1;
      } else if (aNameScore + aGenreScore + a.location > bNameScore + bGenreScore + b.location) {
        return -1;
      } else {
        return 0;
      }
    });

    // Remove duplicates
    results = results.filter((result, index, self) =>
      index === self.findIndex(r => (
        r.name === result.name && r.genre === result.genre && r.city === result.city
      ))
    );
  }

  return results;
}

app.use((req, res, next) => {
  if (req.session.musicianId) {
    const musician = getMusicianById(req.session.musicianId);
    res.locals.musician = musician;
    res.locals.userLoggedIn = true;
    res.locals.username = musician.name;
  } else {
    res.locals.userLoggedIn = false;
  }

  next();
});

app.get("/", (req, res) => {
  const data = fs.readFileSync("./db/musicians.json");
  const musicians = JSON.parse(data);
  const lastRegisteredMusicians = getLastNRegisteredMusicians(5);
  
  res.render("index", { musicians: lastRegisteredMusicians, query:'',city:'',role:''});
  
});

app.get("/autocomplete/cities", async (req, res) => {
  const searchString = req.query.term;
  
  connection.query(
    "SELECT city FROM mytable WHERE city LIKE ?",
    [searchString + '%'],
    (error, results, fields) => {
      if (error) {
        console.error("Ошибка выполнения запроса: ", error);
        res.status(500).send("Ошибка выполнения запроса");
      } else {
        const cities = results.map(row => row.city);
        res.json(cities);
      }
    }
  );
});

app.get("/register", (req, res) => {
  if (req.session.musicianId) {
    const musician = getMusicianById(req.session.musicianId);
    res.redirect("/profile/" + musician.id);
  } else {
	  
	  
	  
    res.render("register", { citiesAndRegions, city:'' });
  }
});

app.post("/register", (req, res) => {
  if (req.session.musicianId) {
    const musician = getMusicianById(req.session.musicianId);
    res.redirect("/profile/" + musician.id);
  } else {
    const data = fs.readFileSync("./db/musicians.json");
    const musicians = JSON.parse(data);

    const newMusician = {
      id: musicians.musicians.length + 1,
      name: req.body.name,
      genre: req.body.genre,
      instrument: req.body.instrument,
      soundcloud: req.body.soundcloud,
      password: req.body.password,
	  role: req.body.role,
	  city: req.body.city,
      login: req.body.login
    };
	
	


    if (req.files && req.files.thumbnail) {
      const file = req.files.thumbnail;
      const filename = "musician_" + newMusician.id + "_" + file.name;
      file.mv("./public/img/" + filename);

      newMusician.thumbnail = filename;
    }
	
	const found = citiesAndRegions.find(
  ({ city }) => city === req.body.city.toLowerCase()
);

// Если найдено - сохраняем город и регион, если нет - оставляем только город
if (found) {
  newMusician.city = found.city;
  newMusician.region = found.region;
} else {
  newMusician.city = req.body.city;
  newMusician.region = "";
}

    musicians.musicians.push(newMusician);
    fs.writeFileSync("./db/musicians.json", JSON.stringify(musicians));

    req.session.musicianId = newMusician.id;
    res.redirect("/profile/" + newMusician.id);
  }
});

app.get("/profile/:id", (req, res) => {
  const musician = getMusicianById(parseInt(req.params.id));

  if (musician) {
    res.render("profile", { musician: musician, city:'', query:'', role:'' });
  } else {
    res.status(404).send("Musician not found");
  }
});

app.get("/login", (req, res) => {
  res.render("login");
});

app.post("/login", (req, res) => {
  const data = fs.readFileSync("./db/musicians.json");
  const musicians = JSON.parse(data);

  const musician = musicians.musicians.find(musician => musician.login === req.body.login && musician.password === req.body.password);

  if (musician) {
    req.session.musicianId = musician.id;
    res.redirect("/profile/" + musician.id);

  } else {
    res.render("login", { error: "Invalid login or password" });
  }
});

app.get("/logout", (req, res) => {
  req.session.destroy();
  res.redirect("/");
});

app.get('/search', (req, res) => {
  const query = req.query.query || '';
  const role = req.query.role || '';
  const city = req.query.city || '';
  const genre = req.query.genre || '';
  
  let musicians = [];

  if (query || role || city || genre) {
    musicians = search(query, role, city, genre);
  } else {
    const data = fs.readFileSync('./db/musicians.json');
    musicians = JSON.parse(data).musicians.map(musician => {
      return {
        name: musician.name,
        genre: musician.genre,
        originalName: musician.name,
        profileLink: `/profile/${musician.id}`,
        thumbnail: musician.thumbnail,
        soundcloud: musician.soundcloud,
        role: musician.role,
		city: musician.city
      };
    });
  }

  //res.locals.predefinedGenres = predefinedGenres;
  app.locals.JSON = JSON;
  res.render('search', { musicians, query, role, city, genre, citiesAndRegions});

  //res.redirect('/search');
});

app.get("/profile/:id/edit", requireLogin, (req, res) => {
  const musician = getMusicianById(parseInt(req.params.id));

  if (musician) {
    if (req.session.musicianId === musician.id) { // Check if the logged-in user is the owner of the profile
      res.render("edit-profile", { musician: musician });
    } else {
      res.status(403).send("Access denied");
    }
  } else {
    res.status(404).send("Musician not found");
  }
});





app.post('/profile/:id/edit', requireLogin, (req, res) => {
  const musician = getMusicianById(parseInt(req.params.id));

  if (musician) {
    if (!req.body.name || !req.body.genre) {
      res.status(400).send('Please fill out all fields');
    
    } else {
      musician.name = req.body.name;
      musician.genre = req.body.genre;
      musician.instrument = req.body.instrument;
      musician.soundcloud = req.body.soundcloud;
	  musician.soundcloud1 = req.body.soundcloud1;
  musician.soundcloud2 = req.body.soundcloud2;
      musician.city = req.body.city;
	  musician.role = req.body.role;
      musician.bio = req.body.bio;

      if (req.files && req.files.thumbnail) {
        const file = req.files.thumbnail;
        const filename = 'musician_' + musician.id + '_' + file.name;
        file.mv('./public/img/' + filename);
        musician.thumbnail = filename;
      }

      const data = fs.readFileSync('./db/musicians.json');
      const musicians = JSON.parse(data);
      const index = musicians.musicians.findIndex(m => m.id === musician.id);
      musicians.musicians[index] = musician;

      fs.writeFileSync('./db/musicians.json', JSON.stringify(musicians));

      res.redirect('/profile/' + musician.id);
    }
  } else {
    res.status(404).send('Musician not found');
  }
  
  
});

function isValidSoundCloudUrl(url) {
  return url.startsWith('https://soundcloud.com/');
}

app.listen(3000, () => {
  console.log("Server started on port 3000");
});

login.ejs:

<!DOCTYPE html>
<html>
  <head>
    <title>Login</title>
  </head>
  <body>
    <h1>Login</h1>
    <form method="post" action="/login">
      <label for="username">Username</label>
      <input type="text" id="username" name="username">
      <label for="password">Password</label>
      <input type="password" id="password" name="password">
      <button type="submit">Login</button>
    </form>
  </body>
</html>