add 401 error page for `basicAuth` mode Most modern browsers don't actually show users 401 responses, but it doesn't hurt to have it in there anyway ¯\_(ツ)_/¯

538d66191e9558b4424d07fbf66aac40185f1c98

Spappz <34202141+Spappz@users.noreply.github.com>

Signed
2 files changed, +20 -1Showing whitespace changes
default/public/error/unauthorized.html+17 -0
@@ -0,0 +1,17 @@
1+<!DOCTYPE html>
2+<html>
3+
4+<head>
5+ <title>Unauthorized</title>
6+</head>
7+
8+<body>
9+ <h1>Unauthorized</h1>
10+ <p>
11+ If you are the system administrator, you can configure the
12+ <code>basicAuthUser</code> credentials by editing
13+ <code>config.yaml</code> in the root directory of your installation.
14+ </p>
15+</body>
16+
17+</html>
src/middleware/basicAuth.js+3 -1
@@ -6,13 +6,15 @@ import { Buffer } from 'node:buffer';
66import storage from 'node-persist';
77import { getAllUserHandles, toKey, getPasswordHash } from '../users.js';
88import { getConfig, getConfigValue } from '../util.js';
9+import { readFileSync } from 'node:fs';
910
1011const PER_USER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false);
1112const ENABLE_ACCOUNTS = getConfigValue('enableUserAccounts', false);
1213
14+const unauthorizedWebpage = readFileSync('./public/error/unauthorized.html', { encoding: 'utf-8' });
1315const unauthorizedResponse = (res) => {
1416 res.set('WWW-Authenticate', 'Basic realm="SillyTavern", charset="UTF-8"');
1517 return res.status(401).send('Authentication required'unauthorizedWebpage);
1618};
1719
1820const basicAuthMiddleware = async function (request, response, callback) {