Skip to content

Commit

Permalink
Create ns on register
Browse files Browse the repository at this point in the history
  • Loading branch information
adb-sh committed Sep 12, 2024
1 parent aa7c1fa commit 7c91319
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { redirect } from "@solidjs/router";
import { useSession } from "vinxi/http";
import { db } from "./db";
import { k8sCore } from "~/k8s";

function validateUsername(username: unknown) {
if (typeof username !== "string" || username.length < 3) {
Expand All @@ -24,6 +25,22 @@ async function login(username: string, password: string) {
async function register(username: string, password: string) {
const existingUser = await db.user.findUnique({ where: { username } });
if (existingUser) throw new Error("User already exists");
try {
await k8sCore.readNamespace(username);
throw new Error("Namespace already exists!");
} catch (e) {}

await k8sCore.createNamespace({
apiVersion: "v1",
kind: "Namespace",
metadata: {
name: username,
labels: {
"app.kubernetes.io/managed-by": "deploycat",
},
},
});

return db.user.create({
data: { username: username, password },
});
Expand Down

0 comments on commit 7c91319

Please sign in to comment.