Skip to main content

Overview

The Users API provides endpoints for managing user accounts, personal information, security settings, and company profiles. All procedures require authentication via protectedProcedure.

Queries

getUserbyUsername

Retrieve a user by their username. Input Parameters:
username
string
required
The unique username to search for
Response:
id
string
Unique user identifier (CUID)
username
string
The user’s username
Example:
const user = await trpc.user.getUserbyUsername.query({ 
  username: "johndoe" 
});

console.log(user); // { id: "clxxx...", username: "johndoe" }

Mutations

updateUserPersonalInfo

Update the authenticated user’s personal information including profile details, contact information, and bio. Input Parameters:
profilePic
string
URL to profile picture
firstName
string
First name (2-30 characters)
lastName
string
Last name (2-30 characters)
email
string
required
Valid email address
phone
string
Valid phone number (validated with libphonenumber-js)
dob
Date
Date of birth
country
string
Country of residence
city
string
City of residence
address
string
Street address
bio
string
User biography
resume
string
URL or text of resume
Example:
await trpc.user.updateUserPersonalInfo.mutate({
  firstName: "John",
  lastName: "Doe",
  email: "[email protected]",
  phone: "+1234567890",
  country: "Morocco",
  city: "Casablanca",
  bio: "Full-stack developer with 5 years experience"
});

updateUserSecurityInfo

Update security-related settings including username, password, and two-factor authentication. Input Parameters:
username
string
New username (2-30 characters, must be unique)
isTwoFactorEnabled
boolean
Enable or disable two-factor authentication
currentpassword
string
Current password (required when changing password, 6-30 characters)
newpassword
string
New password (6-30 characters)
confirmPassword
string
Confirm new password (must match newpassword)
Response:
id
string
User ID
username
string
Updated username
email
string
User email
Errors:
  • BAD_REQUEST: Username already taken
  • BAD_REQUEST: Invalid password
Example:
// Update username
const result = await trpc.user.updateUserSecurityInfo.mutate({
  username: "newusername"
});

// Enable 2FA
await trpc.user.updateUserSecurityInfo.mutate({
  isTwoFactorEnabled: true
});

// Change password
await trpc.user.updateUserSecurityInfo.mutate({
  currentpassword: "oldpass123",
  newpassword: "newpass456",
  confirmPassword: "newpass456"
});

checkUsername

Check if a username is already taken by another user. Input Parameters:
username
string
required
Username to check availability
Response:
username
string
The checked username
isTaken
boolean
Whether the username is already taken
Example:
const check = await trpc.user.checkUsername.mutate({ 
  username: "johndoe" 
});

if (check.isTaken) {
  console.log("Username is not available");
}

updateAccount

Update user account type and username during initial setup. Input Parameters:
signUpAs
enum
required
User role type: "client", "freelancer", or "company"Default: "client"
username
string
required
Desired username
Response:
id
string
User ID
role
string
Updated role (client, freelancer, company)
username
string
Updated username
Errors:
  • BAD_REQUEST: Username already taken
Example:
const user = await trpc.user.updateAccount.mutate({
  signUpAs: "freelancer",
  username: "john_freelancer"
});

createCompany

Create a company profile for users with the “company” role. Input Parameters:
name
string
required
Company name (max 250 characters)
URL to company logo
industry
string
required
Industry sector (max 250 characters)
location
string
required
Company location (max 250 characters)
description
string
required
Company description (max 250 characters)
contactEmail
string
required
Valid contact email address
website
string
Company website URL (max 250 characters)
Response: Returns the created Company object from Prisma. Errors:
  • BAD_REQUEST: User is not signed up as a company
Example:
const company = await trpc.user.createCompany.mutate({
  name: "Tech Solutions Inc",
  logo: "https://example.com/logo.png",
  industry: "Software Development",
  location: "Casablanca, Morocco",
  description: "Leading software development company",
  contactEmail: "[email protected]",
  website: "https://techsolutions.com"
});

Server-Side Functions

These functions are available for server-side use only:

getUserPersonalInfo()

Fetch personal information for the authenticated user from the server session. Returns: User personal info object or null if not authenticated

getUserSecurityInfo()

Fetch security settings for the authenticated user from the server session. Returns: User security info object or null if not authenticated

Build docs developers (and LLMs) love