feat(users): validate usernames before creating or renaming (#610)

This commit is contained in:
Jade
2026-08-25 14:04:49 +09:00
committed by GitHub
parent a5b6ecf28e
commit 03ce112457
5 changed files with 78 additions and 3 deletions
+11
View File
@@ -5,6 +5,7 @@ import { usersResource } from "~/server/headscale/live-store";
import { isUserPrincipal } from "~/server/web/auth";
import { Capabilities } from "~/server/web/roles";
import type { Role } from "~/server/web/roles";
import { validateUsername } from "~/utils/user";
import type { Route } from "./+types/overview";
@@ -42,6 +43,11 @@ export async function userAction({ request, context }: Route.ActionArgs) {
});
}
const nameError = validateUsername(name);
if (nameError) {
throw data(nameError, { status: 400 });
}
await api.users.create({ name, email, displayName });
await headscaleLiveStore.refresh(usersResource, api);
return { message: "User created successfully" };
@@ -65,6 +71,11 @@ export async function userAction({ request, context }: Route.ActionArgs) {
return data({ success: false }, 400);
}
const newNameError = validateUsername(newName);
if (newNameError) {
throw data(newNameError, { status: 400 });
}
const users = await api.users.list({ id: headscaleUserId });
const user = users.find((user) => user.id === headscaleUserId);
if (!user) {