Checks the JSON bodies that the account routes (routes/users.ts, routes/me.ts, routes/sessions.ts) receive before they read them.

Functions

f
fieldOf(
obj: unknown,
key: string
): unknown

Returns obj[key] when obj is an object that has it, else undefined. The users routes whose body has no guard of its own read their fields with it.

f
isLoginUserRequest(obj: unknown): obj is LoginUserRequest

Checks whether obj is a LoginUserRequest. It checks the types only: a wrong name or password is the login route's answer to give.

f
isUpdateUserRequest(obj: unknown): obj is UpdateUserRequest

Checks whether obj is a valid UpdateUserRequest, for PATCH /api/me. Every field is optional, but each one present must be well-formed and within the VALIDATION limits.

f
validateRegisterUserRequest(obj: unknown): string | null

Returns what is wrong with a sign-up body, as the message the register page shows, or null when it is valid. It checks the shape, the email's form, and the username and password against the VALIDATION limits. Whether the name, the email or the invite is taken is createUser's and claimInvite's check.