Enterprise User Authentication
POST/company/auth/login
Endpoint for authenticating administrative users of registered companies.
Performs the following operations:
- Validates email and password format
- Searches for the user in the database (both in company_user and trucker_user as fallback)
- Verifies the password against the stored hash
- Checks the account status (active/blocked)
- Records the last IP and access date
- Generates a JWT token with user claims
- Logs the access in the history
- Verifies/creates a Stripe account if it does not exist
- Retrieves the subscription status
Detailed flow:
- Client sends email and password in JSON format
- Server validates required fields (400 if missing)
- Searches for the user by email (400 if not found)
- Verifies the password with bcrypt (400 if it does not match)
- Checks the account status (401 if inactive/blocked)
- Updates the last access data (IP, date)
- Generates a JWT token with user and company data
- Verifies/creates a Stripe account if it does not exist
- Retrieves the user's subscription status
- 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>