mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
docs(api): 📝 Document API parameter to change username
This commit is contained in:
parent
cfa0ab4ac9
commit
70a669a29c
|
|
@ -61,4 +61,11 @@ An extra attribute has been adding to all returned account objects:
|
||||||
|
|
||||||
### `roles`
|
### `roles`
|
||||||
|
|
||||||
An array of roles from [Lysand Roles](./roles.md).
|
An array of roles from [Lysand Roles](./roles.md).
|
||||||
|
|
||||||
|
### `/api/v1/accounts/update_credentials`
|
||||||
|
|
||||||
|
The `username` parameter can now (optionally) be set to change the user's handle.
|
||||||
|
|
||||||
|
> [!WARNING]
|
||||||
|
> Clients should indicate to users that changing their handle will break existing links to their profile. This is reversible, but the old handle will be available for anyone to claim.
|
||||||
|
|
@ -3,7 +3,7 @@ import { errorResponse, jsonResponse } from "@/response";
|
||||||
import { sanitizedHtmlStrip } from "@/sanitization";
|
import { sanitizedHtmlStrip } from "@/sanitization";
|
||||||
import { zValidator } from "@hono/zod-validator";
|
import { zValidator } from "@hono/zod-validator";
|
||||||
import { config } from "config-manager";
|
import { config } from "config-manager";
|
||||||
import { and, eq } from "drizzle-orm";
|
import { and, eq, isNull } from "drizzle-orm";
|
||||||
import type { Hono } from "hono";
|
import type { Hono } from "hono";
|
||||||
import ISO6391 from "iso-639-1";
|
import ISO6391 from "iso-639-1";
|
||||||
import { MediaBackend } from "media-manager";
|
import { MediaBackend } from "media-manager";
|
||||||
|
|
@ -12,7 +12,7 @@ import { getUrl } from "~/database/entities/attachment";
|
||||||
import { parseEmojis } from "~/database/entities/emoji";
|
import { parseEmojis } from "~/database/entities/emoji";
|
||||||
import { contentToHtml } from "~/database/entities/status";
|
import { contentToHtml } from "~/database/entities/status";
|
||||||
import { db } from "~/drizzle/db";
|
import { db } from "~/drizzle/db";
|
||||||
import { EmojiToUser, RolePermissions } from "~/drizzle/schema";
|
import { EmojiToUser, RolePermissions, Users } from "~/drizzle/schema";
|
||||||
import type { Emoji } from "~/packages/database-interface/emoji";
|
import type { Emoji } from "~/packages/database-interface/emoji";
|
||||||
import { User } from "~/packages/database-interface/user";
|
import { User } from "~/packages/database-interface/user";
|
||||||
|
|
||||||
|
|
@ -191,6 +191,15 @@ export default (app: Hono) =>
|
||||||
}
|
}
|
||||||
|
|
||||||
if (username) {
|
if (username) {
|
||||||
|
// Check if username is already taken
|
||||||
|
const existingUser = await User.fromSql(
|
||||||
|
and(isNull(Users.instanceId), eq(Users.username, username)),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (existingUser) {
|
||||||
|
return errorResponse("Username is already taken", 400);
|
||||||
|
}
|
||||||
|
|
||||||
self.username = username;
|
self.username = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue