mirror of
https://github.com/detleph/server.git
synced 2026-09-04 16:46:04 +02:00
added default admin logic
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import prisma from "../../lib/prisma";
|
||||
import crypto from "crypto";
|
||||
import argon2 from "argon2";
|
||||
import logger from "../error/logger";
|
||||
|
||||
require("express-async-errors");
|
||||
|
||||
export const generateDefaultCredentials = async () => {
|
||||
const name: string = "Detleph_" + crypto.randomBytes(3).toString("base64url");
|
||||
|
||||
const pw: string = crypto.randomBytes(8).toString("base64url");
|
||||
|
||||
await prisma.admin.upsert({
|
||||
where: { id: 1 },
|
||||
create: {
|
||||
name,
|
||||
password: await argon2.hash(pw, { type: argon2.argon2id }),
|
||||
permission_level: "ELEVATED",
|
||||
},
|
||||
update: {},
|
||||
});
|
||||
|
||||
logger.notice("Default admin name is " + name);
|
||||
logger.notice("Confidential password: " + pw);
|
||||
};
|
||||
@@ -19,6 +19,7 @@ import roleRouter from "./Routes/role.routes";
|
||||
import participantRouter from "./Routes/participant.routes";
|
||||
import { notFoundHandler, rootHandler } from "./Middleware/error/defaultRoutes";
|
||||
import { env } from "process";
|
||||
import { generateDefaultCredentials } from "./Middleware/auth/defaultAdmin";
|
||||
|
||||
// Set up async error handling
|
||||
require("express-async-errors");
|
||||
@@ -34,6 +35,7 @@ async function main() {
|
||||
"This mode should not be used in any production-near environment as it is significantly less secure than the production mode"
|
||||
);
|
||||
|
||||
generateDefaultCredentials();
|
||||
// TODO: How should you login to the prod server by default? Maybe random password?
|
||||
await prisma.admin.upsert({
|
||||
where: { id: 1 },
|
||||
@@ -50,6 +52,8 @@ async function main() {
|
||||
} else {
|
||||
logger.info("Using production mode");
|
||||
|
||||
generateDefaultCredentials();
|
||||
|
||||
// Configure cors
|
||||
/*app.use(
|
||||
cors({
|
||||
|
||||
Reference in New Issue
Block a user