Skip to main content

Enterprise User Authentication

POST 

/company/auth/login

Endpoint for authenticating administrative users of registered companies.
Performs the following operations:

  1. Validates email and password format
  2. Searches for the user in the database (both in company_user and trucker_user as fallback)
  3. Verifies the password against the stored hash
  4. Checks the account status (active/blocked)
  5. Records the last IP and access date
  6. Generates a JWT token with user claims
  7. Logs the access in the history
  8. Verifies/creates a Stripe account if it does not exist
  9. Retrieves the subscription status

Detailed flow:

  1. Client sends email and password in JSON format
  2. Server validates required fields (400 if missing)
  3. Searches for the user by email (400 if not found)
  4. Verifies the password with bcrypt (400 if it does not match)
  5. Checks the account status (401 if inactive/blocked)
  6. Updates the last access data (IP, date)
  7. Generates a JWT token with user and company data
  8. Verifies/creates a Stripe account if it does not exist
  9. Retrieves the user's subscription status
  10. Returns the token with the user's complete data

Security:

  • Requires HTTPS
  • Passwords are transmitted hashed
  • Tokens have a configurable expiration

Example request:

{
email: admin@company.com,
password: SecurePassword123!
}

Example successful response:

\{
token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...,
expiresIn: 1712345678901,
_id: 507f1f77bcf86cd799439011,
role: admin,
status: true,
emailVerified: true,
refresh_time: 3,
name: Juan,
lastname: Pérez García,
country: esp,
accountType: multitenant,
hasSign: true,
hasPaymentMethod: true,
subscriptionStatus: \{
hasSubscription: true,
subscriptionType

<Heading
id={"request"}
as={"h2"}
className={"openapi-tabs__heading"}
children={"Request"}
>
</Heading>

<ParamsDetails
parameters={[]}
>

</ParamsDetails>

<RequestSchema
title={"Body"}
body={{"content":{"application/json":{"schema":{"type":"object","properties":{"email":{"type":"string","format":"email","description":"User's email","example":"admin@empresa.com"},"password":{"type":"string","format":"password","description":"User password","example":"Contraseña123!"}},"required":["email","password"],"title":"LoginRequest"},"example":{"email":"companytest@test.com","password":"Test1234"}}},"required":true}}
>

</RequestSchema>

<StatusCodes
id={undefined}
label={undefined}
responses={{"200":{"description":"Successful authentication","content":{"application/json":{"schema":{"type":"object","properties":{"token":{"type":"string","description":"JWT token for authentication","example":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."},"expiresIn":{"type":"integer","format":"int64","description":"Token expiration timestamp in milliseconds (Unix epoch)","example":1712345678901},"_id":{"type":"string","description":"User ID","example":"507f1f77bcf86cd799439011"},"role":{"type":"string","description":"User role in the system","enum":["admin","gestor","dev"],"example":"admin"},"status":{"type":"boolean","description":"User account status","example":true},"emailVerified":{"type":"boolean","description":"Indicate whether the email has been verified","example":true},"refresh_time":{"type":"integer","description":"Token refresh time in hours","example":3},"name":{"type":"string","description":"User's name","example":"Juan"},"lastname":{"type":"string","description":"User's Last Names","example":"Pérez García"},"country":{"type":"string","description":"User's country code","example":"esp"},"accountType":{"type":"string","description":"Account Type","example":"multitennant"},"hasSign":{"type":"boolean","description":"Indicate whether the account has a digital signature configured.","example":true},"hasPaymentMethod":{"type":"boolean","description":"Indicate if the account has a payment method configured","example":true},"subscriptionStatus":{"type":"object","description":"User subscription status","properties":{"hasSubscription":{"type":"boolean","description":"Indicates if you have an active subscription","example":true},"subscriptionType":{"type":"string","description":"Subscription type","example":"Basic Plan"}}}},"title":"TokenResponse"}}},"headers":{}},"400":{"description":"Missing data or incorrect credentials","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"integer","example":400},"message":{"type":"string","enum":["FORM_DATA_NOT_VALID","WRONG_CREDENTIALS"],"example":"WRONG_CREDENTIALS"}}}}},"headers":{}},"401":{"description":"Invalid user or company","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"integer","example":401},"message":{"type":"string","enum":["CIA_NOT_FOUND","USER_NOT_ACTIVE","ACCOUNT_BLOCKED"],"example":"USER_NOT_ACTIVE"}}}}},"headers":{}}}}
>

</StatusCodes>