mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-01-31 15:37:09 +01:00
feat: run tasks at startup
This commit is contained in:
27
server/plugins/02.setup-admin.ts
Normal file
27
server/plugins/02.setup-admin.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import prisma from "~/server/internal/db/database";
|
||||
|
||||
export default defineNitroPlugin(async (_nitro) => {
|
||||
const userCount = await prisma.user.count({
|
||||
where: { id: { not: "system" } },
|
||||
});
|
||||
if (userCount != 0) return;
|
||||
|
||||
// This setup runs every time the server sets up,
|
||||
// but has not been configured
|
||||
// so it should be in-place
|
||||
|
||||
// Create admin invitation
|
||||
await prisma.invitation.upsert({
|
||||
where: {
|
||||
id: "admin",
|
||||
},
|
||||
create: {
|
||||
id: "admin",
|
||||
isAdmin: true,
|
||||
expires: new Date("4096-01-01"),
|
||||
},
|
||||
update: {
|
||||
isAdmin: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user