Skip to main content
POST
/
api
/
admin-auth
/
crear-auth
Create Supabase Auth User
curl --request POST \
  --url https://api.example.com/api/admin-auth/crear-auth \
  --header 'Content-Type: application/json' \
  --data '
{
  "email": "<string>",
  "password": "<string>"
}
'
{
  "auth_user_id": "<string>"
}

Overview

Creates a new user in Supabase Auth with email and password. This is an admin-only endpoint used to provision new system users.
Admin OnlyThis endpoint requires authentication with the admin role. The created user must then be registered in the internal usuarios table using POST /api/usuarios.

Request Body

email
string
required
The email address for the new user
password
string
required
The password for the new user

Response

auth_user_id
string
The Supabase Auth UUID for the created user. Use this ID when creating the corresponding record in /api/usuarios.

Example Request

cURL
curl -X POST http://localhost:3000/api/admin-auth/crear-auth \
  -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "password": "SecurePassword123!"
  }'
JavaScript
const response = await fetch('http://localhost:3000/api/admin-auth/crear-auth', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${adminToken}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    email: '[email protected]',
    password: 'SecurePassword123!'
  })
});
const data = await response.json();
console.log(data.auth_user_id); // Use this UUID in POST /api/usuarios

Example Response

200 OK
{
  "auth_user_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}

Error Responses

{
  "message": "Email y contraseña son obligatorios"
}
Missing required email or password fields.
{
  "message": "User already registered"
}
The email address is already registered in Supabase Auth.
{
  "message": "Token requerido"
}
No authentication token provided.
{
  "message": "Acceso denegado"
}
User does not have admin role.

Two-Step User Creation Process

Creating a complete system user requires two API calls:
1

Create Supabase Auth User

Use this endpoint to create the authentication user:
POST /api/admin-auth/crear-auth
Save the returned auth_user_id.
2

Create Internal User Record

Use the UUID from step 1 to create the internal user record:
POST /api/usuarios
{
  "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "role": "asistente",
  "persona_id": 5
}
The user is created with email_confirm: true, so they can log in immediately without email verification.
Source: /home/daytona/workspace/source/src/routes/adminAuth.routes.js:12

Build docs developers (and LLMs) love