Skip to content

Authentication API

The Authentication API provides user login, session management, and token handling.

Overview

ProcedureTypeAuthDescription
auth.loginMutationNoLogin with email/password
auth.meQueryYesGet current user info
auth.refreshTokenMutationYesRefresh JWT token
auth.logoutMutationNoLogout (client-side)

Procedures

auth.login

Authenticate a user and receive a JWT token.

Type: Mutation Auth Required: No

Input

typescript
{
  email: string;    // Valid email address
  password: string; // User password
}

Response

typescript
{
  token: string;
  user: {
    id: string;
    email: string;
    firstName: string;
    lastName: string;
    role: "ADMIN" | "OPERATOR" | "VIEWER";
  }
}

Example

bash
curl -X POST "https://api.itms.solutions/trpc/auth.login" \
  -H "Content-Type: application/json" \
  -d '{
    "json": {
      "email": "admin@itms.solutions",
      "password": "Admin@123"
    }
  }'

Response Example

json
{
  "result": {
    "data": {
      "json": {
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
        "user": {
          "id": "admin-001",
          "email": "admin@itms.solutions",
          "firstName": "System",
          "lastName": "Administrator",
          "role": "ADMIN"
        }
      }
    }
  }
}

Errors

CodeDescription
UNAUTHORIZEDInvalid email or password
INTERNAL_SERVER_ERRORDatabase not available

auth.me

Get the currently authenticated user's information.

Type: Query Auth Required: Yes

Headers

http
Authorization: Bearer <jwt-token>

Response

typescript
{
  id: string;
  email: string;
  firstName: string;
  lastName: string;
  role: string;
  createdAt: string;
  updatedAt: string;
}

Example

bash
curl -X GET "https://api.itms.solutions/trpc/auth.me" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Errors

CodeDescription
UNAUTHORIZEDNo token provided or invalid token
NOT_FOUNDUser not found

auth.refreshToken

Refresh an existing JWT token before it expires.

Type: Mutation Auth Required: Yes

Headers

http
Authorization: Bearer <current-jwt-token>

Response

typescript
{
  token: string;      // New JWT token
  expiresIn: number;  // Seconds until expiration (86400 = 24 hours)
  user: {
    id: string;
    email: string;
    firstName: string;
    lastName: string;
    role: string;
  }
}

Example

bash
curl -X POST "https://api.itms.solutions/trpc/auth.refreshToken" \
  -H "Authorization: Bearer YOUR_CURRENT_TOKEN"

Errors

CodeDescription
UNAUTHORIZEDInvalid or expired token

auth.logout

Logout the current user. This is primarily a client-side operation.

Type: Mutation Auth Required: No

Response

typescript
{
  success: boolean;
}

Example

bash
curl -X POST "https://api.itms.solutions/trpc/auth.logout"

JWT Token Details

  • Algorithm: HS256
  • Expiration: 24 hours
  • Payload Contents:
    • id - User ID
    • email - User email
    • role - User role
    • firstName - User first name
    • lastName - User last name
    • exp - Expiration timestamp

User Roles

RoleDescription
ADMINFull system access
OPERATORCan manage sensors and view reports
VIEWERRead-only access

Password Security

  • Passwords are hashed using bcrypt
  • Minimum recommended: 8 characters
  • Salt rounds: 10

SCS Smart City - Traffic, Gateway, Camera, and NVR Platform