📋 Overview
The Byve Registration API provides a centralized authentication system for all Byve platform applications. It supports user registration, password-based login, and OTP-based authentication via email.
🎯 Features
- User Registration
- Password Authentication
- OTP Email Verification
- JWT Token Generation
- Secure Password Hashing
🔒 Security
- BCrypt Password Hashing
- JWT Bearer Tokens
- API Key Authentication
- OTP Expiration (5 mins)
- HTTPS Only
- Rate Limiting (1000/hour)
📧 Email Features
- Beautiful HTML Templates
- SMTP Integration
- OTP Delivery
- Security Warnings
- Professional Design
🌐 API Endpoints
Base URL: https://registrationapi.byve.io/api/auth
Description: Register a new user account with email, phone, and password
Auth Required: X-API-Key header (Production only)
Request Body:
{
"firstName": "string" (required, max 100 chars),
"lastName": "string" (required, max 100 chars),
"email": "string" (required, valid email format),
"phoneNumber": "string" (required, valid phone format),
"password": "string" (required, min 8 chars),
"confirmPassword": "string" (required, must match password)
}
Response: 200 OK with JWT token and user details, or 400 Bad Request
Description: Login with email/phone and password
Auth Required: X-API-Key header (Production only)
Request Body:
{
"identifier": "string" (required, email OR phone number),
"password": "string" (required)
}
Response: 200 OK with JWT token and user details, or 401 Unauthorized
Description: Request OTP code via email for passwordless login
Auth Required: X-API-Key header (Production only)
Request Body:
{
"identifier": "string" (required, email OR phone number)
}
Response: 200 OK with success message (OTP sent to email)
Note: OTP valid for 5 minutes, check email inbox
Description: Verify OTP code and receive JWT token
Auth Required: X-API-Key header (Production only)
Request Body:
{
"identifier": "string" (required, email OR phone number),
"code": "string" (required, 6-digit OTP code)
}
Response: 200 OK with JWT token and user details, or 401 Unauthorized
💻 Complete Integration Guide
Follow these step-by-step examples to integrate the Byve Registration API into your application.
Step 1: Register a New User
// Registration function with validation
const registerUser = async (userData) => {
try {
const response = await fetch('https://registrationapi.byve.io/api/auth/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your-api-key-here' // Production only, remove in dev
},
body: JSON.stringify({
firstName: userData.firstName,
lastName: userData.lastName,
email: userData.email,
phoneNumber: userData.phoneNumber,
password: userData.password,
confirmPassword: userData.confirmPassword
})
});
const data = await response.json();
if (data.success) {
// Store JWT token
localStorage.setItem('authToken', data.token);
console.log('Registration successful:', data.user);
return { success: true, user: data.user };
} else {
console.error('Registration failed:', data.message);
return { success: false, error: data.message };
}
} catch (error) {
console.error('Network error:', error);
return { success: false, error: 'Network error occurred' };
}
};
// Example usage
registerUser({
firstName: 'John',
lastName: 'Doe',
email: 'john@example.com',
phoneNumber: '+1234567890',
password: 'SecurePass123!',
confirmPassword: 'SecurePass123!'
});
Step 2: Login with Password
// Password login function
const loginWithPassword = async (identifier, password) => {
try {
const response = await fetch('https://registrationapi.byve.io/api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your-api-key-here' // Production only
},
body: JSON.stringify({
identifier: identifier, // Email or phone number
password: password
})
});
const data = await response.json();
if (data.success) {
// Store JWT token
localStorage.setItem('authToken', data.token);
console.log('Login successful:', data.user);
return { success: true, user: data.user, token: data.token };
} else {
console.error('Login failed:', data.message);
return { success: false, error: data.message };
}
} catch (error) {
console.error('Network error:', error);
return { success: false, error: 'Network error occurred' };
}
};
// Example usage
await loginWithPassword('john@example.com', 'SecurePass123!');
Step 3: Request OTP (Passwordless Login)
// Request OTP code
const requestOTP = async (identifier) => {
try {
const response = await fetch('https://registrationapi.byve.io/api/auth/otp/request', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your-api-key-here' // Production only
},
body: JSON.stringify({
identifier: identifier // Email or phone number
})
});
const data = await response.json();
if (data.success) {
console.log('OTP sent successfully:', data.message);
return { success: true, message: 'Check your email for OTP code' };
} else {
console.error('OTP request failed:', data.message);
return { success: false, error: data.message };
}
} catch (error) {
console.error('Network error:', error);
return { success: false, error: 'Network error occurred' };
}
};
// Example usage
await requestOTP('john@example.com');
Step 4: Verify OTP and Login
// Verify OTP code and login
const verifyOTP = async (identifier, otpCode) => {
try {
const response = await fetch('https://registrationapi.byve.io/api/auth/otp/verify', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your-api-key-here' // Production only
},
body: JSON.stringify({
identifier: identifier,
code: otpCode // 6-digit code from email
})
});
const data = await response.json();
if (data.success) {
// Store JWT token
localStorage.setItem('authToken', data.token);
console.log('OTP verified, logged in:', data.user);
return { success: true, user: data.user, token: data.token };
} else {
console.error('OTP verification failed:', data.message);
return { success: false, error: data.message };
}
} catch (error) {
console.error('Network error:', error);
return { success: false, error: 'Network error occurred' };
}
};
// Example usage
await verifyOTP('john@example.com', '123456');
Step 5: Using JWT Token for Protected Requests
// Make authenticated requests with JWT token
const makeAuthenticatedRequest = async (endpoint, method = 'GET', body = null) => {
const token = localStorage.getItem('authToken');
if (!token) {
console.error('No auth token found');
return { success: false, error: 'Not authenticated' };
}
try {
const options = {
method: method,
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
};
if (body) {
options.body = JSON.stringify(body);
}
const response = await fetch(endpoint, options);
if (response.status === 401) {
// Token expired or invalid
localStorage.removeItem('authToken');
console.error('Token expired, please login again');
return { success: false, error: 'Token expired' };
}
const data = await response.json();
return data;
} catch (error) {
console.error('Request failed:', error);
return { success: false, error: 'Request failed' };
}
};
// Example: Get user profile (if you have such endpoint)
// await makeAuthenticatedRequest('https://registrationapi.byve.io/api/user/profile');
OTP Login (Verify)
const verifyOtp = async (otpCode) => {
const response = await fetch('https://registrationapi.byve.io/api/auth/otp/verify', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your-api-key-here' // Production only
},
body: JSON.stringify({
identifier: 'john@example.com',
code: otpCode
})
});
const { token, user } = await response.json();
localStorage.setItem('authToken', token);
console.log('Logged in:', user);
};