Register a new user account and receive a JWT token
curl --request POST \
--url https://api.example.com/api/register \
--header 'Content-Type: <content-type>' \
--header 'x-api-key: <x-api-key>' \
--data '
{
"name": "<string>",
"email": "<string>",
"password": "<string>"
}
'{
"status": "<string>",
"message": "<string>",
"data": {
"token": "<string>"
}
}Documentation Index
Fetch the complete documentation index at: https://mintlify.com/memoowi/e-comm-api-demo-2/llms.txt
Use this file to discover all available pages before exploring further.
POST http://localhost:5000/api/register
application/jsonShow data
export const register = async (req, res) => {
const { name, email, password } = req.body;
if (!name || !email || !password) {
return errorResponse({
res,
statusCode: 400,
message: "All fields are required",
});
}
try {
const [existingUser] = await db.execute(
"SELECT * FROM users WHERE email = ?",
[email]
);
if (existingUser.length > 0) {
return errorResponse({
res,
statusCode: 409,
message: "Email is already registered",
});
}
const hashedPassword = await bcrypt.hash(password, 10);
const [result] = await db.execute(
"INSERT INTO users (name, email, password) VALUES (?, ?, ?)",
[name, email, hashedPassword]
);
const token = jwt.sign(
{ id: result.insertId, email, name },
process.env.JWT_SECRET,
{ expiresIn: "8h" }
);
successResponse({
res,
statusCode: 201,
message: "User Registered",
data: { token },
});
} catch (err) {
errorResponse({ res, statusCode: 500, message: "Internal Server Error" });
}
};
curl -X POST http://localhost:5000/api/register \
-H "x-api-key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com",
"password": "securepassword123"
}'
{
"status": "OK",
"message": "User Registered",
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}
{
"status": "ERROR",
"message": "All fields are required",
"data": null
}
{
"status": "ERROR",
"message": "Invalid API Key",
"data": null
}
{
"status": "ERROR",
"message": "Email is already registered",
"data": null
}
{
"status": "ERROR",
"message": "Internal Server Error",
"data": null
}
Authorization: Bearer <token>
{
"id": 1,
"email": "john@example.com",
"name": "John Doe",
"iat": 1234567890,
"exp": 1234596690
}
curl --request POST \
--url https://api.example.com/api/register \
--header 'Content-Type: <content-type>' \
--header 'x-api-key: <x-api-key>' \
--data '
{
"name": "<string>",
"email": "<string>",
"password": "<string>"
}
'{
"status": "<string>",
"message": "<string>",
"data": {
"token": "<string>"
}
}