Skip to main content
POST
/
auth
/
register
Register
curl --request POST \
  --url https://api.example.com/auth/register
{
  "success": true,
  "message": "<string>",
  "data": {
    "user": {
      "id": 123,
      "role": "<string>",
      "name": "<string>",
      "email": "<string>",
      "phone": "<string>"
    }
  }
}

Endpoint

POST /auth/register
Register a new user account. Creates a user with the default “USER” role.
This endpoint does not require authentication (unauthenticated).

Request Body

name
string
required
User’s full name. Minimum 2 characters.Validation: required|string|min:2
phone
string
required
User’s phone number. Minimum 10 characters.Validation: required|string|min:10
email
string
required
User’s email address. Must be a valid email format and unique in the system.Validation: required|email|unique:users
password
string
required
User’s password. Minimum 8 characters. Must be confirmed.Validation: required|confirmed|min:8
password_confirmation
string
required
Password confirmation. Must match the password field.Validation: Must match password field

Response

success
boolean
required
Indicates if the request was successful
message
string
required
Human-readable success message
data
object
required
Contains the newly created user information

Code Examples

curl -X POST "https://api.servitech.com/auth/register" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "name": "John Doe",
    "phone": "+1234567890",
    "email": "[email protected]",
    "password": "SecurePass123",
    "password_confirmation": "SecurePass123"
  }'

Success Response

HTTP Status: 201 Created
{
  "success": true,
  "message": "User registered successfully",
  "data": {
    "user": {
      "id": 42,
      "role": "USER",
      "name": "John Doe",
      "email": "[email protected]",
      "phone": "+1234567890"
    }
  }
}

Error Responses

Validation Errors

HTTP Status: 422 Unprocessable Entity Returned when request data fails validation.

Missing Required Fields

{
  "success": false,
  "message": "The given data was invalid.",
  "errors": {
    "name": [
      "The name field is required."
    ],
    "phone": [
      "The phone field is required."
    ],
    "email": [
      "The email field is required."
    ],
    "password": [
      "The password field is required."
    ]
  }
}

Invalid Email Format

{
  "success": false,
  "message": "The given data was invalid.",
  "errors": {
    "email": [
      "The email must be a valid email address."
    ]
  }
}

Email Already Exists

{
  "success": false,
  "message": "The given data was invalid.",
  "errors": {
    "email": [
      "The email has already been taken."
    ]
  }
}

Password Too Short

{
  "success": false,
  "message": "The given data was invalid.",
  "errors": {
    "password": [
      "The password must be at least 8 characters."
    ]
  }
}

Password Confirmation Mismatch

{
  "success": false,
  "message": "The given data was invalid.",
  "errors": {
    "password": [
      "The password confirmation does not match."
    ]
  }
}

Name Too Short

{
  "success": false,
  "message": "The given data was invalid.",
  "errors": {
    "name": [
      "The name must be at least 2 characters."
    ]
  }
}

Phone Too Short

{
  "success": false,
  "message": "The given data was invalid.",
  "errors": {
    "phone": [
      "The phone must be at least 10 characters."
    ]
  }
}

Implementation Details

The registration process follows these steps (from AuthController.php:130-146):
  1. Validate Request - Validates all fields using RegisterUserRequest rules
  2. Create User - Creates user with validated data
  3. Assign Role - Automatically assigns “USER” role to new account
  4. Return Response - Returns user data with HTTP 201 status
Source Code Reference: AuthController.php:130-146
public function register(RegisterUserRequest $request): JsonResponse
{
    $user = User::create($request->validated());
    $user->assignRole(UserRoles::USER);

    return ApiResponse::success(
        message: __('messages.user.registered'),
        status: Response::HTTP_CREATED,
        data: ['user' => UserResource::make($user)]
    );
}
The password is automatically hashed before storage using Laravel’s built-in hashing. Never store passwords in plain text.

Next Steps After Registration

After successful registration, you typically need to:
  1. Login - Authenticate to receive a JWT token
  2. Complete Profile - Add additional user information if needed
  3. Verify Email - If email verification is enabled (not documented in current implementation)

Auto-Login After Registration

The current implementation does NOT automatically log in users after registration. To log in immediately:
// Register user
const registerResponse = await fetch('https://api.servitech.com/auth/register', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  },
  body: JSON.stringify({
    name: 'John Doe',
    phone: '+1234567890',
    email: '[email protected]',
    password: 'SecurePass123',
    password_confirmation: 'SecurePass123'
  })
});

const registerData = await registerResponse.json();

if (registerData.success) {
  // Auto-login after successful registration
  const loginResponse = await fetch('https://api.servitech.com/auth/login', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json'
    },
    body: JSON.stringify({
      email: '[email protected]',
      password: 'SecurePass123'
    })
  });
  
  const loginData = await loginResponse.json();
  
  if (loginData.success) {
    const token = loginData.data.token;
    localStorage.setItem('jwt_token', token);
    console.log('Registered and logged in successfully!');
  }
}

User Roles

All newly registered users receive the USER role by default (as defined in UserRoles::USER). Available Roles:
  • USER - Standard user with basic permissions
  • ADMIN - Administrator with elevated permissions
Admin role cannot be assigned through registration. Admin accounts must be created manually or through an admin promotion endpoint (if available).

Password Requirements

Current password validation:
  • Minimum length: 8 characters
  • Confirmation: Required
  • Hashing: Automatic using bcrypt
Consider implementing additional password strength requirements in production:
  • At least one uppercase letter
  • At least one lowercase letter
  • At least one number
  • At least one special character

Login

Authenticate after registration

Password Reset

Reset forgotten password

User Profile

Manage user profile information

Build docs developers (and LLMs) love