Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

1.0 KB
Raw Blame
import { command } from "@drizzle-team/brocli";

import { db, eq } from "@homarr/db";
import { users } from "@homarr/db/schema";

export const fixUsernames = command({
  name: "fix-usernames",
  desc: "Changes all credentials usernames to lowercase",
  // eslint-disable-next-line no-restricted-syntax
  handler: async () => {
    if (!process.env.AUTH_PROVIDERS?.toLowerCase().includes("credentials")) {
      throw new Error("Credentials provider is not enabled");
    }

    const credentialUsers = await db.query.users.findMany({
      columns: { id: true, name: true },
      where: eq(users.provider, "credentials"),
    });

    for (const user of credentialUsers) {
      if (!user.name) continue;
      if (user.name === user.name.toLowerCase()) continue;

      await db
        .update(users)
        .set({
          name: user.name.toLowerCase(),
        })
        .where(eq(users.id, user.id));

      console.log(`Changed username from ${user.name} to ${user.name.toLowerCase()}`);
    }

    console.log("All usernames have been fixed");
  },
});