nextjs-basic-auth icon indicating copy to clipboard operation
nextjs-basic-auth copied to clipboard

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

Open ant-ms opened this issue 3 years ago • 1 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>')
}

ant-ms avatar Apr 27 '22 18:04 ant-ms

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

chris13524 avatar May 26 '22 13:05 chris13524