curl --request POST \
--url https://api.example.com/api/v1/auths/sign-up \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"password": "<string>",
"first_name": "<string>",
"last_name": "<string>",
"username": "<string>",
"phone": "<string>"
}
'{
"400": {},
"409": {},
"500": {},
"accessToken": "<string>",
"refreshToken": "<string>",
"user": {
"id": 123,
"username": "<string>",
"email": "<string>",
"firstName": "<string>",
"lastName": "<string>",
"role": "<string>",
"avatar": "<string>",
"status": "<string>",
"lastLogin": "<string>",
"createdAt": "<string>",
"permissions": [
{}
],
"stats": {}
}
}Create a new user account
curl --request POST \
--url https://api.example.com/api/v1/auths/sign-up \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"password": "<string>",
"first_name": "<string>",
"last_name": "<string>",
"username": "<string>",
"phone": "<string>"
}
'{
"400": {},
"409": {},
"500": {},
"accessToken": "<string>",
"refreshToken": "<string>",
"user": {
"id": 123,
"username": "<string>",
"email": "<string>",
"firstName": "<string>",
"lastName": "<string>",
"role": "<string>",
"avatar": "<string>",
"status": "<string>",
"lastLogin": "<string>",
"createdAt": "<string>",
"permissions": [
{}
],
"stats": {}
}
}firstname_lastname (lowercase)Example: John Doe → john_doeShow User Object Properties
comentar: Can comment on postscrear_post: Can create new postseditar_post_propio: Can edit own postsreaccionar: Can react to contentpostsCreated: 0postsPublished: 0totalViews: 0interface RegisterData {
email: string;
password: string;
first_name: string;
last_name: string;
username?: string;
phone?: string;
}
interface RegisterResponse {
accessToken: string;
refreshToken: string;
user: {
id: number;
email: string;
username: string;
firstName: string;
lastName: string;
role: string;
avatar: string;
status: string;
lastLogin: string;
createdAt: string;
permissions: string[];
stats: {
postsCreated: number;
postsPublished: number;
totalViews: number;
};
};
}
async function register(userData: RegisterData): Promise<RegisterResponse> {
const response = await fetch('https://api.example.com/api/v1/auths/sign-up', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(userData),
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.message || 'Registration failed');
}
const data = await response.json();
// Store tokens securely
localStorage.setItem('access_token', data.accessToken);
localStorage.setItem('refresh_token', data.refreshToken);
localStorage.setItem('user_data', JSON.stringify(data.user));
return data;
}
// Usage
const newUser = await register({
email: '[email protected]',
password: 'SecurePass123!',
first_name: 'John',
last_name: 'Doe',
phone: '+1234567890'
});
console.log('Registered and logged in as:', newUser.user.email);
{
"statusCode": 409,
"message": "Email already registered"
}
{
"statusCode": 400,
"message": "Validation failed",
"errors": [
"email must be a valid email",
"password must be at least 6 characters",
"first_name is required"
]
}
{
"statusCode": 500,
"message": "Failed to create user account"
}
async function checkEmailAvailability(email: string): Promise<boolean> {
const response = await fetch('https://api.example.com/api/v1/auths/validate-email', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email }),
});
const data = await response.json();
return !data.exists; // Returns true if email is available
}
// Usage
const isAvailable = await checkEmailAvailability('[email protected]');
if (!isAvailable) {
console.log('Email already registered');
}
first_name and last_name in the format firstname_lastname (lowercase)"autor" (Author)"active"comentar, crear_post, editar_post_propio, reaccionar)