Node js express Error [ERR_HTTP_HEADERS_SENT]

В файле admin-v.hbs базовая разметка страницы + форма авторизации:

<html lang="ru">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Вход в панель Администратора</title>
</head>

<body>
  <style>
    body {
      background-color: rgba(0, 0, 0, 0.722);
      color: white;
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      margin: 0;
    }
    
    h1 {
      text-align: center;
    }
    
    form {
      text-align: center;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }
    
    @media screen and (min-width: 600px) {
      .i1 {
        text-align: center;
        background-color: transparent;
        border: 3px solid rgb(165, 165, 165);
        padding: 10px;
        width: 25vw;
        margin: 20px;
        color: white;
        font-size: 1.4em;
        border-radius: 5px;
      }
      .i2 {
        text-align: center;
        background-color: transparent;
        border: 3px solid rgb(165, 165, 165);
        padding: 10px;
        width: 20vw;
        margin: 20px;
        color: white;
        font-size: 1.4em;
        border-radius: 20px;
        cursor: pointer;
        transition: all 0.5s;
      }
    }
    
    @media screen and (max-width: 599px) {
      .i1 {
        text-align: center;
        background-color: transparent;
        border: 3px solid rgb(165, 165, 165);
        padding: 10px;
        width: 80%;
        margin: 20px;
        color: white;
        font-size: 1.4em;
        border-radius: 5px;
      }
      .i2 {
        text-align: center;
        background-color: transparent;
        border: 3px solid rgb(165, 165, 165);
        padding: 10px;
        width: 70%;
        margin: 20px;
        color: white;
        font-size: 1.4em;
        border-radius: 20px;
        cursor: pointer;
        transition: all 0.5s;
      }
    }
    
    .i2:hover {
      width: 60%;
    }
    
    input::placeholder {
      color: #ffffff;
    }
    
    #items {
      width: 100%;
      height: 100%;
    }
    
    #item {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100%;
      flex-direction: column;
      position: relative;
      z-index: 999;
    }
    
    #img {
      margin: 0;
      width: 100%;
      height: 100%;
      position: fixed;
      background-size: cover;
      object-fit: cover;
      filter: blur(5px) brightness(50%);
    }
  </style>
  <img src="https://avatars.mds.yandex.net/i?id=be175ebf98cc6ef7fc074b130ccbf8ea-5410808-images-thumbs&n=13" id="img" alt="">
  <div class="content">
    <div id="items">
      <div id="item">
        <h1>Вход в панель Администратора</h1>
        <form action="/admin" method="get">
          <input class="i1" type="text" name="name" autocomplete="off" placeholder="Логин" required />
          <input class="i1" type="text" name="key" autocomplete="off" placeholder="Пароль" required />
          <input class="i2" type="submit" value="Войти" />
        </form>
      </div>
    </div>
  </div>
</body>

</html>

В node js я провожу вход в бд и проверяю данные:

app.get("/admin", function(req, res) {
  let key = req.query.key;
  let name = req.query.name;
  for (var g = 0; g < security.length; g++) {
    if (name == security[g].name && key == security[g].pass) {
      res.render("admin", {
        name: security[g].name,
        lvl: security[g].lvl,
      });
    } else {
      res.render("admin-v");
    }
  }
});

Т.е. если верно, то переводит на саму админку, в противном случае опять рендерится admin-v.hbs, но тут возникает проблема, я не могу ее решить, из за нее он игнорирует мои данные для входа, и тупо выполняет else условие.

Вот проблема:

Error[ERR_HTTP_HEADERS_SENT]: D: \WEBIK\ NODE - JS\ views\ admin - v.hbs: Cannot set headers after they are sent to the client
at new NodeError(node: internal / errors: 399: 5)
at ServerResponse.setHeader(node: _http_outgoing: 644: 11)
at ServerResponse.header(D: \WEBIK\ NODE - JS\ node_modules\ express\ lib\ response.js: 794: 10)
at ServerResponse.send(D: \WEBIK\ NODE - JS\ node_modules\ express\ lib\ response.js: 174: 12)
at done(D: \WEBIK\ NODE - JS\ node_modules\ express\ lib\ response.js: 1035: 10)
at D: \WEBIK\ NODE - JS\ node_modules\ hbs\ lib\ hbs.js: 99: 11
at Object.done(D: \WEBIK\ NODE - JS\ node_modules\ hbs\ lib\ async.js: 74: 20)
at D: \WEBIK\ NODE - JS\ node_modules\ hbs\ lib\ hbs.js: 94: 20
at FSReqCallback.readFileAfterClose[as oncomplete](node: internal / fs / read_file_context: 68: 3)


Ответы (0 шт):