Home / Docs Center / Pet Feeder (ODM Case) / Register & Login

Register & Login

Pet Feeder (ODM Case) · App Server-Side API

Project: Pet Feeder | page_id: 1721

User Registration and Login Interface Documentation

Overview

  • Base path: /api
  • Unified response format:
{
  "code": 200,
  "msg": "Operation successful",
  "data": {}
}

Field description:

  • code: business status code; 200 means success, other values mean failure
  • msg: response message
  • data: business data, may be null

1. Send Verification Code

  • Path: /api/user/sendCode
  • Method: POST
  • Authentication required: No
  • Content-Type: application/json

Request Parameters

Field Type Required Description
phone string Yes Mobile phone number, the length must be 11
source int Yes Verification code source, 1=login, 2=registration, 3=password recovery

Request Example

{
"phone": "13800138000",
"source": 2
}

Success Response Example

{
  "code": 200,
  "msg": "Verification code sent successfully",
  "data": {
    "expireSeconds": 300
  }
}

Failure Response Example

{
  "code": 400,
  "msg": "Incorrect mobile phone number format",
  "data": null
}
{
  "code": 400,
  "msg": "Incorrect verification code source",
  "data": null
}

Description:

  • The server generates a random 6-digit verification code.
  • The verification code is valid for 300 seconds.
  • Verification codes with different source values are stored separately and do not affect each other.
  • When the same mobile phone number already has a verification code under the same source and the remaining validity period is greater than 60 seconds, the server directly returns success without sending the SMS again.
  • source=1 uses the general login verification code template, source=2 uses the registration verification code template, and source=3 uses the password recovery verification code template.

2. User Registration

  • Path: /api/user/register
  • Method: POST
  • Authentication required: No
  • Content-Type: application/json

Request Parameters

Field Type Required Description
phone string Yes Mobile phone number
code string Yes Verification code
password string No Password; if not provided, a password-free account is created
nickname string No Nickname, up to 30 characters

Request Example

{
  "phone": "13800138000",
  "code": "123456",
  "password": "12345678",
  "nickname": "Xiaoming"
}

Success Response Example

{
  "code": 200,
  "msg": "Registration successful",
  "data": null
}

Failure Response Example

{
  "code": 400,
  "msg": "Incorrect or expired verification code",
  "data": null
}
{
  "code": 400,
  "msg": "This mobile phone number is already registered",
  "data": null
}
{
  "code": 400,
  "msg": "The nickname cannot exceed 30 characters",
  "data": null
}

Description:

  • After registration succeeds, the token is not returned directly; you need to call the login interface to obtain it.
  • Verification code validation uses one-time consumption (GetDel); the same verification code cannot be used repeatedly.

3. User Login

  • Path: /api/user/login
  • Method: POST
  • Authentication required: No
  • Content-Type: application/json

Request Parameters

Field Type Required Description
phone string Yes Mobile phone number
code string No Verification code login; choose one of code and password, code takes priority
password string No Password login

Request Example (Verification Code Login)

{
  "phone": "13800138000",
  "code": "123456"
}

Request Example (Password Login)

{
  "phone": "13800138000",
  "password": "12345678"
}

Success Response Example

{
  "code": 200,
  "msg": "Login successful",
  "data": {
    "id": 1,
    "phone": "13800138000",
    "nickname": "Xiaoming",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI...",
    "expiresIn": 86400
  }
}

Failure Response Example

{
  "code": 400,
  "msg": "User does not exist",
  "data": null
}
{
  "code": 400,
  "msg": "Please provide a verification code or password",
  "data": null
}
{
  "code": 400,
  "msg": "Incorrect or expired verification code",
  "data": null
}
{
  "code": 400,
  "msg": "Incorrect password",
  "data": null
}

Appendix

Login Logic Priority

  • When code is not empty, verification code login takes priority.
  • Password login is used only when code is empty and password is not empty.

Token Usage

  • After login succeeds, put the token in the Authorization request header.
  • Interfaces requiring authentication have their token verified by the server-side Auth middleware.
Didn't find what you need?Contact us,Talk to our engineers directly.

Request a Quote

Fill in the form and we will get back with a quote and proposal within 1 business day.

Click "Generate inquiry email" to open your mail client with the body pre-filled. If no mail client is configured, click "Copy" and paste it into webmail — recipient: sunshiyang@xstrive.com.