Update server setup logic and add admin user creation in setup page

This commit is contained in:
Sean Morley
2024-04-18 23:00:35 +00:00
parent 7fe90f615f
commit f626370d3f
9 changed files with 235 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import { db } from "$lib/db/db.server";
import { userTable } from "$lib/db/schema";
import { eq } from "drizzle-orm";
import { Argon2id } from "oslo/password";
import type { DatabaseUser } from "$lib/server/auth";
export const load: PageServerLoad = async (event) => {
if (event.locals.user)
@@ -42,6 +43,22 @@ export const actions: Actions = {
};
}
const usernameTaken = await db
.select()
.from(userTable)
.where(eq(userTable.username, username))
.limit(1)
.then((results) => results[0] as unknown as DatabaseUser | undefined);
if (usernameTaken) {
return {
status: 400,
body: {
message: "Username taken!"
}
};
}
if (password) {
let hashedPassword = await new Argon2id().hash(password);
console.log(hashedPassword)