mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-27 17:00:54 +01:00
feat(cli): add fix-username command to make all usernames lowercase (#2366)
* feat(cli): add fix-username command to make all usernames lowercase * fix: add missing command
This commit is contained in:
36
packages/cli/src/commands/fix-usernames.ts
Normal file
36
packages/cli/src/commands/fix-usernames.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
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")) {
|
||||
console.error("Credentials provider is not enabled");
|
||||
return;
|
||||
}
|
||||
|
||||
const credentialUsers = await db.query.users.findMany({
|
||||
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");
|
||||
},
|
||||
});
|
||||
@@ -1,8 +1,9 @@
|
||||
import { run } from "@drizzle-team/brocli";
|
||||
|
||||
import { fixUsernames } from "./commands/fix-usernames";
|
||||
import { resetPassword } from "./commands/reset-password";
|
||||
|
||||
const commands = [resetPassword];
|
||||
const commands = [resetPassword, fixUsernames];
|
||||
|
||||
void run(commands, {
|
||||
name: "homarr-cli",
|
||||
|
||||
Reference in New Issue
Block a user