fix(api): maybe fix default user not being created

This commit is contained in:
diced 2021-09-05 09:13:13 -07:00
parent 6f5f9869ad
commit 38217870fe
No known key found for this signature in database
GPG key ID: 85AB64C74535D76E

View file

@ -1,6 +1,6 @@
import prisma from 'lib/prisma';
import { NextApiReq, NextApiRes, withZipline } from 'middleware/withZipline';
import { checkPassword } from 'lib/util';
import { checkPassword, createToken, hashPassword } from 'lib/util';
import Logger from 'lib/logger';
import prismaRun from '../../../../scripts/prisma-run';
import config from 'lib/config';
@ -11,7 +11,16 @@ async function handler(req: NextApiReq, res: NextApiRes) {
const users = await prisma.user.findMany();
if (users.length === 0) {
await prismaRun(config.core.database_url, ['db', 'seed', '--preview-feature']);
Logger.get('database').info('no users found... creating default user...');
await prisma.user.create({
data: {
username: 'administrator',
password: await hashPassword('password'),
token: createToken(),
administrator: true
}
});
Logger.get('database').info('created default user:\nUsername: "administrator"\nPassword: "password"');
}
const user = await prisma.user.findFirst({