Endpoint
Checks whether a username is available. Returns true if the username is available or already belongs to the authenticated user.
Authentication
Requires authentication via session cookie.
Request
Response
true if the username is available or belongs to the current user, false if taken by another user
Example
import { client } from '@/lib/client';
const result = await client.profile.checkUsername({
username: "johndoe"
});
console.log(result);
// { available: true }
Schema
const usernameSchema = z
.string()
.min(3, "Username must be at least 3 characters")
.max(39, "Username must be at most 39 characters")
.regex(
/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/,
"Lowercase letters, numbers, and hyphens only. Must start and end with a letter or number."
)
.refine((val) => !val.includes("--"), "Username cannot contain consecutive hyphens")
.refine((val) => !RESERVED_USERNAMES.has(val), "This username is reserved");
Notes
- Username is automatically converted to lowercase before checking
- Returns
true if the username belongs to the authenticated user (useful for validation during profile updates)
- Username must pass validation rules (no reserved words, valid format)
Source
- Schema:
lib/schema.ts:16
- Implementation:
server/procedures/profile.ts:65
- Router:
server/router.ts:47