feature: Changes root tokens to use a special field.

This makes it not have to look through the entire database to figure out your user.
This commit is contained in:
greysoh 2024-04-21 16:10:56 -04:00
parent 86e5728d6c
commit cc737ca7d3
No known key found for this signature in database
GPG key ID: FE0F173B8FC01571
2 changed files with 8 additions and 2 deletions

View file

@ -69,7 +69,11 @@ export async function hasPermissionByToken(permissionList: string[], token: stri
// Fine, we'll look up for global tokens... // Fine, we'll look up for global tokens...
// FIXME: Could this be more efficient? IDs are sequential in SQL I think // FIXME: Could this be more efficient? IDs are sequential in SQL I think
if (userID == -1) { if (userID == -1) {
const allUsers = await prisma.user.findMany(); const allUsers = await prisma.user.findMany({
where: {
isRootServiceAccount: true
}
});
for (const user of allUsers) { for (const user of allUsers) {
if (user.rootToken == token) userID = user.id; if (user.rootToken == token) userID = user.id;

View file

@ -76,7 +76,9 @@ export function route(fastify: FastifyInstance, prisma: PrismaClient, tokens: Re
if (options.allowUnsafeGlobalTokens) { if (options.allowUnsafeGlobalTokens) {
// @ts-ignore // @ts-ignore
userData.rootToken = generateToken() as unknown as null; userData.rootToken = generateToken();
// @ts-ignore
userData.isRootServiceAccount = true;
} }
const userCreateResults = await prisma.user.create({ const userCreateResults = await prisma.user.create({