jchiatt / nextjs-basic-auth

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pressing the OK button twice in quick succesion will load the page.

1Yanik3 opened this issue · comments

As the title says, Pressing the OK button twice in quick succession will load the page even when no login data is entered. When I then reload the page, I get an "unauthorized" though. In the console I get this error: uncaughtException: Error [ERR_STREAM_WRITE_AFTER_END]: write after end.
(no idea why, but this only seems to happen in Firefox (tried an multiple devices))

I've used this piece of code to fix it temporarily:

if (!users.some(({ user, password }) => base64.encode(`${user}:${password}`) == req.headers.authorization.split(" ")[1])) {
  res.end('<html>Unauthorized</html>')
}

Could the problem be that res.end("Unauthorized") is only called when no authorization header is provided but not when the authorization fails?