Skip to main content

POST /api/access-code

Validates an access code and attempts to add the authenticated user as a participant to the corresponding virtual class. Returns the Google Meet link if successful.

Authentication

This endpoint requires authentication. The user must be logged in with a valid session.

Request Body

The request body should be a plain string containing the access code.
accessCode
string
required
8-character uppercase alphanumeric access code for the classExample: "A1B2C3D4"

Response

response
object
Response object containing class information or error message

Example Request

curl -X POST https://your-domain.com/api/access-code \
  -H "Content-Type: application/json" \
  -H "Cookie: authjs.session-token=YOUR_SESSION_TOKEN" \
  -d '"A1B2C3D4"'

Example Success Response

{
  "response": {
    "id": "65f8a3b2c1d4e5f6a7b8c9d0",
    "bookedById": "65f7a2b1c0d3e4f5a6b7c8d9",
    "htmlLink": "https://meet.google.com/abc-defg-hij",
    "startTime": "2026-03-15T10:00:00.000Z",
    "endTime": "2026-03-15T11:00:00.000Z",
    "classType": "grupal",
    "currentParticipants": 3,
    "maxParticipants": 5
  }
}

Example Error Responses

Validation Flow

When an access code is submitted, the system:
  1. Looks up the virtual class by access code
  2. Validates that the class exists
  3. Checks if the requesting user is the class creator (not allowed to join as participant)
  4. Verifies the class has not ended
  5. Confirms the class has not reached maximum capacity
  6. Checks if the user is already registered
  7. Adds the user as a participant in a transaction:
    • Creates a UserActivity record with role "participante"
    • Increments currentParticipants counter
    • Adds user ID to participantsIds array
  8. Returns the class details including the Google Meet link

Notes

  • Access codes are 8-character uppercase alphanumeric strings generated automatically when a class is scheduled
  • The access code validation uses a database transaction to ensure data consistency
  • Users can only join classes that haven’t ended yet
  • The class creator cannot join their own class as a participant (they are automatically the host)
  • Each user can only join a class once

Build docs developers (and LLMs) love