mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
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 ¯\_(ツ)_/¯
This commit is contained in:
17
default/public/error/unauthorized.html
Normal file
17
default/public/error/unauthorized.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Unauthorized</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Unauthorized</h1>
|
||||
<p>
|
||||
If you are the system administrator, you can configure the
|
||||
<code>basicAuthUser</code> credentials by editing
|
||||
<code>config.yaml</code> in the root directory of your installation.
|
||||
</p>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -6,13 +6,15 @@ import { Buffer } from 'node:buffer';
|
||||
import storage from 'node-persist';
|
||||
import { getAllUserHandles, toKey, getPasswordHash } from '../users.js';
|
||||
import { getConfig, getConfigValue } from '../util.js';
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
const PER_USER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false);
|
||||
const ENABLE_ACCOUNTS = getConfigValue('enableUserAccounts', false);
|
||||
|
||||
const unauthorizedWebpage = readFileSync('./public/error/unauthorized.html', { encoding: 'utf-8' });
|
||||
const unauthorizedResponse = (res) => {
|
||||
res.set('WWW-Authenticate', 'Basic realm="SillyTavern", charset="UTF-8"');
|
||||
return res.status(401).send('Authentication required');
|
||||
return res.status(401).send(unauthorizedWebpage);
|
||||
};
|
||||
|
||||
const basicAuthMiddleware = async function (request, response, callback) {
|
||||
|
||||
Reference in New Issue
Block a user