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:
parent
86e5728d6c
commit
cc737ca7d3
2 changed files with 8 additions and 2 deletions
|
@ -69,7 +69,11 @@ export async function hasPermissionByToken(permissionList: string[], token: stri
|
|||
// Fine, we'll look up for global tokens...
|
||||
// FIXME: Could this be more efficient? IDs are sequential in SQL I think
|
||||
if (userID == -1) {
|
||||
const allUsers = await prisma.user.findMany();
|
||||
const allUsers = await prisma.user.findMany({
|
||||
where: {
|
||||
isRootServiceAccount: true
|
||||
}
|
||||
});
|
||||
|
||||
for (const user of allUsers) {
|
||||
if (user.rootToken == token) userID = user.id;
|
||||
|
|
|
@ -76,7 +76,9 @@ export function route(fastify: FastifyInstance, prisma: PrismaClient, tokens: Re
|
|||
|
||||
if (options.allowUnsafeGlobalTokens) {
|
||||
// @ts-ignore
|
||||
userData.rootToken = generateToken() as unknown as null;
|
||||
userData.rootToken = generateToken();
|
||||
// @ts-ignore
|
||||
userData.isRootServiceAccount = true;
|
||||
}
|
||||
|
||||
const userCreateResults = await prisma.user.create({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue