add single-user authentication

This commit is contained in:
2025-09-12 14:45:06 +00:00
parent 742a3e2143
commit bb4c94f0f6
5 changed files with 34 additions and 8 deletions

View File

@@ -45,10 +45,12 @@ export function getNewKey(user) {
return apiKey;
}
async function createApiKeys(client, user) {
async function createApiKeys(client, user, issuer) {
const config = getConfig();
for (const type in config.appModules) {
const apiKey = getNewKey(user);
const apiKey = issuer !== 'https://single'
? getNewKey(user)
: config.authModules.single[type]
await client.query(`
INSERT INTO public.auth (
user_id,
@@ -149,11 +151,10 @@ export async function checkUser(type, issuer, identifier, username, photo) {
photo,
type,
]);
console.log(res.rows[0])
if (res.rowCount === 0) {
return null;
}
await createApiKeys(client, res.rows[0]);
await createApiKeys(client, res.rows[0], issuer);
} else {
if (photo !== userExists.rows[0].photo || username != userExists.rows[0].username) {
await client.query(`
@@ -168,7 +169,7 @@ export async function checkUser(type, issuer, identifier, username, photo) {
userExists.rows[0].id,
]);
}
await createApiKeys(client, userExists.rows[0]);
await createApiKeys(client, userExists.rows[0], issuer);
}
const user = await getUser(client, issuer, identifier);
return user;

View File

@@ -0,0 +1,18 @@
import { checkUser } from "../../http/auth.js";
import { getConfig } from "../../common/config.js";
const key = 'single';
export function getModuleConfig() {
const config = getConfig();
return {
core: process.env.SINGLE_API_KEY_CORE,
archive: process.env.SINGLE_API_KEY_ARCHIVE,
}
}
export async function initModule(app, passport) {
if (process.env.SINGLE_API_KEY_CORE && process.env.SINGLE_API_KEY_ARCHIVE) {
await checkUser(key, 'https://single', 'single', 'single');
}
}