Skip to main content
POST
/
api
/
v1
/
auth
/
register
Register
curl --request POST \
  --url https://api.example.com/api/v1/auth/register \
  --header 'Content-Type: application/json' \
  --data '
{
  "company_name": "<string>",
  "tax_id": "<string>",
  "email": "<string>",
  "password": "<string>",
  "first_name": "<string>",
  "last_name": "<string>",
  "phone": "<string>",
  "address": "<string>"
}
'
{
  "200": {},
  "400": {},
  "token": "<string>",
  "type": "<string>",
  "username": "<string>",
  "roles": [
    "<string>"
  ]
}

Overview

Register a new company in the Invernaderos system. This endpoint creates both a tenant (company entity) and an admin user in a single atomic transaction. The admin user receives full access to manage greenhouses, sensors, and users within their tenant.

Request Body

company_name
string
required
Name of the company/tenantValidation:
  • Must not be blank
  • Length: 2-100 characters
Example: "Greenhouse Tech"
tax_id
string
required
Tax identification number (NIF/CIF in Spain, VAT number in EU)Validation: Must not be blankExample: "B12345678"
email
string
required
Admin user’s email address (also used as username for login)Validation:
  • Must not be blank
  • Must be valid email format
  • Must be unique (not already registered)
Example: "[email protected]"
password
string
required
Admin user’s passwordValidation:
  • Must not be blank
  • Minimum length: 6 characters
Example: "securePass123"
first_name
string
required
Contact person’s first nameValidation: Must not be blankExample: "John"
last_name
string
required
Contact person’s last nameValidation: Must not be blankExample: "Doe"
phone
string
Contact phone numberExample: "+34600123456"
address
string
Physical address of the companyExample: "Calle Principal 123, Madrid"

Response

Upon successful registration, the user is automatically logged in and receives a JWT token.
token
string
required
JWT access token for the newly created admin user
type
string
required
Token type, always returns "Bearer"
username
string
required
Email address of the newly created admin user
roles
string[]
required
Roles assigned to the user. For new registrations, always includes ["ROLE_ADMIN"]

Registration Flow

1

Validate Input

The API validates all required fields and checks email uniqueness
2

Create Tenant

A new tenant (company) is created with:
  • Auto-generated unique tenant code
  • Company name from request
  • Contact information (email, phone, address)
  • Active status set to true
3

Create Admin User

An admin user is created and associated with the new tenant:
  • Auto-generated unique user code
  • Email as username
  • Password is securely hashed using BCrypt
  • Role set to "ADMIN"
  • Active status set to true
4

Auto-Login

The user is automatically logged in:
  • JWT token is generated with tenantId and role claims
  • Token and user details are returned in response

Example Request

curl -X POST https://api.invernaderos.com/api/v1/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "company_name": "Greenhouse Tech",
    "tax_id": "B12345678",
    "email": "[email protected]",
    "password": "securePass123",
    "first_name": "John",
    "last_name": "Doe",
    "phone": "+34600123456",
    "address": "Calle Principal 123, Madrid"
  }'

Example Response

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbkBncmVlbmhvdXNldGVjaC5jb20iLCJ0ZW5hbnRJZCI6IjU1MGU4NDAwLWUyOWItNDFkNC1hNzE2LTQ0NjY1NTQ0MDAwMCIsInJvbGUiOiJBRE1JTiIsImlhdCI6MTcwMDAwMDAwMCwiZXhwIjoxNzAwMDg2NDAwfQ.signature",
  "type": "Bearer",
  "username": "[email protected]",
  "roles": ["ROLE_ADMIN"]
}

Status Codes

200
OK
Successfully registered. Tenant and admin user created. JWT token returned.
400
Bad Request
Registration failed due to validation errors or duplicate email.Common causes:
  • Email already registered
  • Password too short (< 6 characters)
  • Company name too short (< 2 characters) or too long (> 100 characters)
  • Invalid email format
  • Missing required fields

Multi-Tenant Isolation

Each registered company becomes an isolated tenant in the system. All data (greenhouses, sensors, users) is automatically scoped to the tenant based on the JWT token’s tenantId claim.Tenant Isolation Ensures:
  • Company A cannot see Company B’s greenhouses or sensor data
  • Each tenant has independent user management
  • Cross-tenant API access is prevented at the database level

Admin User Privileges

The newly created admin user has full access to:

Validation Rules

The following validation rules are enforced:
FieldRuleError Message
company_name2-100 characters”Company Name must be between 2 and 100 characters”
tax_idNot blank”Tax ID is required”
emailValid email format”Invalid email format”
emailUnique”Email already in use”
passwordMin 6 characters”Password must be at least 6 characters long”
first_nameNot blank”First Name is required”
last_nameNot blank”Last Name is required”

Database Schema

Source Code References

  • Controller: AuthController.kt:27-36 - Register endpoint definition
  • Service: AuthService.kt:42-68 - Registration logic
  • DTO: AuthDTOs.kt:19-54 - RegisterRequest structure
  • User Service: UserService.kt:121-158 - Tenant and user creation
  • Response: AuthDTOs.kt:56-62 - JwtResponse structure

Build docs developers (and LLMs) love