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...
|
// 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;
|
||||||
|
|
|
@ -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({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue