Skip to main content
POST
/
auth
/
register
Register
curl --request POST \
  --url https://api.example.com/auth/register \
  --header 'Content-Type: application/json' \
  --data '
{
  "first_name": "<string>",
  "last_name": "<string>",
  "email": "<string>",
  "password": "<string>",
  "role": "<string>",
  "phone": "<string>",
  "mobile": "<string>",
  "birth_date": "<string>",
  "street": "<string>",
  "postal_code": "<string>",
  "city": "<string>",
  "country": "<string>",
  "biography": "<string>",
  "job": "<string>",
  "portfolio": "<string>",
  "youtube": "<string>",
  "instagram": "<string>",
  "linkedin": "<string>",
  "facebook": "<string>",
  "tiktok": "<string>",
  "known_by_mars_ai": "<string>"
}
'
{
  "message": "<string>",
  "newUser": {
    "id_user": 123,
    "first_name": "<string>",
    "last_name": "<string>",
    "email": "<string>",
    "role": "<string>",
    "password": "<string>",
    "phone": "<string>",
    "mobile": "<string>",
    "birth_date": "<string>",
    "street": "<string>",
    "postal_code": "<string>",
    "city": "<string>",
    "country": "<string>",
    "biography": "<string>",
    "job": "<string>",
    "portfolio": "<string>",
    "youtube": "<string>",
    "instagram": "<string>",
    "linkedin": "<string>",
    "facebook": "<string>",
    "tiktok": "<string>",
    "known_by_mars_ai": "<string>",
    "createdAt": "<string>",
    "updatedAt": "<string>"
  }
}

Overview

Creates a new user account with the provided information. Passwords are automatically hashed using bcrypt before storage. The endpoint supports both camelCase (frontend) and snake_case (database) field naming conventions.

Request

Body Parameters

Required Fields

first_name
string
required
User’s first name. Also accepts firstName (camelCase)
last_name
string
required
User’s last name. Also accepts lastName (camelCase)
email
string
required
User’s email address. Must be unique in the system.
password
string
required
User’s password in plain text. Will be hashed with bcrypt before storage.
role
string
default:"PRODUCER"
User’s role on the platform. Defaults to “PRODUCER” if not specified.Possible values:
  • PRODUCER: Film producer/submitter
  • ADMIN: Platform administrator
  • JURY: Festival jury member

Optional Fields

phone
string
User’s phone number
mobile
string
User’s mobile phone number
birth_date
string
User’s birth date. Also accepts birthDate (camelCase). If empty or ‘Invalid date’, will be set to null.
street
string
Street address
postal_code
string
Postal/ZIP code. Also accepts postalCode (camelCase)
city
string
City name
country
string
Country name
biography
string
User’s biography or description
job
string
User’s job title or profession
portfolio
string
Portfolio URL
youtube
string
YouTube channel or profile URL
instagram
string
Instagram profile URL or username
linkedin
string
LinkedIn profile URL
facebook
string
Facebook profile URL
tiktok
string
TikTok profile URL or username
known_by_mars_ai
string
How the user learned about MarsAI. Also accepts knownByMarsAi (camelCase)

Request Example

cURL
curl -X POST https://api.marsai.com/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "first_name": "Jane",
    "last_name": "Doe",
    "email": "jane.doe@example.com",
    "password": "securePassword123",
    "role": "PRODUCER",
    "phone": "+33612345678",
    "city": "Paris",
    "country": "France",
    "job": "Film Director",
    "known_by_mars_ai": "Social media"
  }'
JavaScript
const response = await fetch('https://api.marsai.com/auth/register', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    firstName: 'Jane',        // camelCase also supported
    lastName: 'Doe',
    email: 'jane.doe@example.com',
    password: 'securePassword123',
    role: 'PRODUCER',
    phone: '+33612345678',
    city: 'Paris',
    country: 'France',
    job: 'Film Director'
  })
});

const data = await response.json();
console.log(data);

Response

Success Response (201)

User account created successfully.
message
string
Success message: “Utilisateur créé avec succès”
newUser
object
The newly created user object

Example Response

{
  "message": "Utilisateur créé avec succès",
  "newUser": {
    "id_user": 42,
    "first_name": "Jane",
    "last_name": "Doe",
    "email": "jane.doe@example.com",
    "password": "$2b$10$abcdefghijklmnopqrstuvwxyz1234567890",
    "role": "PRODUCER",
    "phone": "+33612345678",
    "mobile": null,
    "birth_date": null,
    "street": null,
    "postal_code": null,
    "city": "Paris",
    "country": "France",
    "biography": null,
    "job": "Film Director",
    "portfolio": null,
    "youtube": null,
    "instagram": null,
    "linkedin": null,
    "facebook": null,
    "tiktok": null,
    "known_by_mars_ai": "Social media",
    "createdAt": "2026-03-07T10:30:00.000Z",
    "updatedAt": "2026-03-07T10:30:00.000Z"
  }
}

Error Responses

400 Bad Request
Missing required fields or invalid data
{
  "error": "Tous les champs sont requis"
}
This error occurs when:
  • first_name, last_name, email, password, or role is missing
  • Request body is empty
{
  "error": "Données manquantes"
}
200 OK (Duplicate)
Email already exists in the databaseNote: This returns 200 instead of 409, which is non-standard but matches the current implementation.
{
  "message": "Cet utilisateur existe déjà",
  "user": {
    "id_user": 15,
    "email": "jane.doe@example.com",
    "first_name": "Jane",
    "last_name": "Doe",
    "role": "PRODUCER"
  }
}
500 Internal Server Error
Database error during user creation
{
  "error": "Erreur base de données",
  "details": "Detailed error message"
}
This error occurs when:
  • Database connection fails
  • Constraint violation (other than unique email)
  • Password hashing fails

Implementation Details

Registration Flow

  1. Validation: Checks for required fields and validates data format
  2. Duplicate Check: Verifies email doesn’t already exist (User.findOne({ where: { email } }))
  3. Password Hashing: Hashes password using bcrypt (hashPassword(password))
  4. User Creation: Creates user record in database with all provided fields
  5. Response: Returns success message with new user object

Field Name Compatibility

The endpoint accepts both naming conventions:
  • Frontend camelCase: firstName, lastName, birthDate, postalCode, knownByMarsAi
  • Database snake_case: first_name, last_name, birth_date, postal_code, known_by_mars_ai

Source Code Reference

Registration delegated to: back/src/controllers/UserController.js:82-178
function createUser(req, res) {
  // Field mapping for camelCase/snake_case compatibility
  let {
    first_name, firstName,
    last_name, lastName,
    email, password, role,
    // ... other fields
  } = req.body;

  first_name = first_name || firstName;
  last_name = last_name || lastName;
  // ... mapping for other fields

  if (!role) {
    role = "PRODUCER";  // Default role
  }

  // Validate required fields
  if (!first_name || !last_name || !email || !password || !role) {
    return res.status(400).json({ error: "Tous les champs sont requis" });
  }

  // Check for existing user
  User.findOne({ where: { email } }).then(async (user) => {
    if (user) {
      res.json({ message: "Cet utilisateur existe déjà", user });
    } else {
      // Hash password and create user
      const hash = await hashPassword(password);
      
      User.create({
        first_name, last_name, email,
        password: hash, role,
        // ... all other fields
      })
      .then((newUser) => {
        res.status(201).json({ 
          message: "Utilisateur créé avec succès", 
          newUser 
        });
      });
    }
  });
}
Route definition: back/src/routes/Auth.route.js:41

Next Steps

After registration, users should:
  1. Use the Login endpoint to authenticate and receive a JWT token
  2. Include the JWT token in subsequent API requests for protected routes