| 6 | 6 | import storage from 'node-persist'; |
| 7 | 7 | import { getAllUserHandles, toKey, getPasswordHash } from '../users.js'; |
| 8 | 8 | import { getConfig, getConfigValue } from '../util.js'; |
| 9 | +import { readFileSync } from 'node:fs'; |
| 9 | 10 | |
| 10 | 11 | const PER_USER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false); |
| 11 | 12 | const ENABLE_ACCOUNTS = getConfigValue('enableUserAccounts', false); |
| 12 | 13 | |
| 14 | +const unauthorizedWebpage = readFileSync('./public/error/unauthorized.html', { encoding: 'utf-8' }); |
| 13 | 15 | const unauthorizedResponse = (res) => { |
| 14 | 16 | res.set('WWW-Authenticate', 'Basic realm="SillyTavern", charset="UTF-8"'); |
| 15 | 17 | return res.status(401).send('Authentication required'unauthorizedWebpage); |
| 16 | 18 | }; |
| 17 | 19 | |
| 18 | 20 | const basicAuthMiddleware = async function (request, response, callback) { |