Use the authentication method system for the demo login and the generated accounts. This makes it possible to toggle it off on production systems as these shouldn't have it enabled at all.
20 lines
848 B
TypeScript
20 lines
848 B
TypeScript
/*
|
|
SPDX-FileCopyrightText: © 2025 Hornwitser <code@hornwitser.no>
|
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
import { nextAuthenticationMethodId, writeAuthenticationMethods, writeNextAuthenticationMethodId, writeSchedule, writeUsers } from "~/server/database";
|
|
import { generateDemoSchedule, generateDemoAccounts } from "~/server/generate-demo-schedule";
|
|
export default defineEventHandler(async (event) => {
|
|
await requireServerSessionWithAdmin(event);
|
|
const accounts = generateDemoAccounts();
|
|
await writeUsers(accounts);
|
|
await writeSchedule(generateDemoSchedule());
|
|
await writeAuthenticationMethods(accounts.map((user, index) => ({
|
|
id: index,
|
|
userId: user.id,
|
|
provider: "demo",
|
|
slug: user.name!,
|
|
name: user.name!,
|
|
})));
|
|
await writeNextAuthenticationMethodId(Math.max(await nextAuthenticationMethodId(), accounts.length));
|
|
})
|