nextjs-basic-auth
nextjs-basic-auth copied to clipboard
Pressing the OK button twice in quick succesion will load the page.
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?