Auth API#
API xác thực người dùng: đăng ký, đăng nhập, xác thực email, đổi mật khẩu, xác thực số điện thoại.
Base URL: https://app.socialking.vn/api/v1
1. Đăng ký tài khoản#
POST /auth/signup
#
Auth: Không cần
Request Body:
{
"name": "Nguyen Van A",
"email": "user@example.com",
"password": "Password@123"
}| Field | Type | Required | Validation |
|---|---|---|---|
name | string | Yes | 2-100 ký tự |
email | string | Yes | Email hợp lệ, lowercase, max 100 ký tự, unique |
password | string | Yes | 8-50 ký tự, ít nhất 1 chữ hoa, 1 chữ thường, 1 số, 1 ký tự đặc biệt |
Response (201):
{
"success": true,
"message": "Đăng ký thành công! Vui lòng kiểm tra email để xác thực tài khoản.",
"data": {
"email": "user@example.com",
"role": "user"
}
}Errors:
| Code | Mô tả |
|---|---|
| 400 | Validation error (email invalid, password yếu) |
| 409 | Email đã tồn tại |
2. Xác thực Email#
POST /auth/verify-email
#
Auth: Không cần
Request Body:
{
"email": "user@example.com",
"otp": "123456"
}| Field | Type | Required | Validation |
|---|---|---|---|
email | string | Yes | Email hợp lệ |
otp | string | Yes | Đúng 6 chữ số |
Response (200):
{
"success": true,
"message": "Xác thực email thành công! Bạn có thể đăng nhập ngay bây giờ.",
"data": {
"email": "user@example.com",
"userId": "uuid-string",
"name": "Nguyen Van A"
}
}3. Gửi lại Email xác thực#
POST /auth/resend-email
#
Auth: Không cần
Request Body:
{
"email": "user@example.com"
}| Field | Type | Required | Validation |
|---|---|---|---|
email | string | Yes | Email hợp lệ, lowercase, max 100 ký tự |
Response (200):
{
"success": true,
"message": "Email xác thực đã được gửi lại.",
"data": {
"email": "user@example.com",
"expiresIn": "10 phút"
}
}4. Quên mật khẩu#
POST /auth/forgot-password
#
Auth: Không cần
Request Body:
{
"email": "user@example.com"
}| Field | Type | Required | Validation |
|---|---|---|---|
email | string | Yes | Email hợp lệ, lowercase, max 100 ký tự |
Response (200):
{
"success": true,
"message": "Email đặt lại mật khẩu đã được gửi.",
"data": {
"email": "user@example.com",
"expiresIn": "10 phút"
}
}5. Đặt lại mật khẩu#
POST /auth/reset-password
#
Auth: Không cần
Request Body:
{
"token": "reset-token-from-email",
"email": "user@example.com",
"newPassword": "NewPassword@123",
"confirmPassword": "NewPassword@123"
}| Field | Type | Required | Validation |
|---|---|---|---|
token | string | Yes | Token từ email |
email | string | No | Email hợp lệ, lowercase |
newPassword | string | Yes | 8-50 ký tự, 1 chữ hoa, 1 chữ thường, 1 số, 1 ký tự đặc biệt |
confirmPassword | string | Yes | Phải khớp với newPassword |
Response (200):
{
"success": true,
"message": "Đặt lại mật khẩu thành công"
}6. Đổi mật khẩu#
POST /auth/change-password
#
Auth: Bearer Token (JWT)
Request Body:
{
"oldPassword": "OldPassword@123",
"newPassword": "NewPassword@456"
}| Field | Type | Required | Validation |
|---|---|---|---|
oldPassword | string | Yes | Mật khẩu hiện tại |
newPassword | string | Yes | 8-50 ký tự, 1 chữ hoa, 1 chữ thường, 1 số, 1 ký tự đặc biệt |
Response (200):
{
"success": true,
"message": "Đổi mật khẩu thành công"
}7. Đăng xuất#
POST /auth/log-out
#
Auth: Tùy chọn
Request Body: Không cần
Response (200):
{
"success": true,
"message": "Đăng xuất thành công"
}8. Kiểm tra Session#
GET /auth/verify-session
#
Auth: Không cần
Response (200):
{
"success": true,
"data": {
"id": "uuid",
"email": "user@example.com",
"name": "Nguyen Van A"
}
}9. Gửi OTP Số điện thoại#
POST /auth/send-phone-otp
#
Auth: Bearer Token (JWT)
Rate Limit: 5 req/phút
Request Body:
{
"phone": "0912345678"
}| Field | Type | Required | Validation |
|---|---|---|---|
phone | string | Yes | Số điện thoại VN: 0|+84|84 + 3|5|7|8|9 + 8 chữ số |
Response (200):
{
"success": true,
"message": "OTP đã được gửi"
}10. Xác thực Số điện thoại#
POST /auth/verify-phone
#
Auth: Bearer Token (JWT)
Rate Limit: 10 req/phút
Request Body:
{
"phone": "0912345678",
"otp": "123456"
}| Field | Type | Required | Validation |
|---|---|---|---|
phone | string | Yes | Số điện thoại VN hợp lệ |
otp | string | Yes | Đúng 6 chữ số |
Response (200):
{
"success": true,
"message": "Xác thực số điện thoại thành công"
}11. Gửi lại OTP Số điện thoại#
POST /auth/resend-phone-otp
#
Auth: Bearer Token (JWT)
Rate Limit: 3 req/phút
Request Body:
{
"phone": "0912345678"
}| Field | Type | Required | Validation |
|---|---|---|---|
phone | string | Yes | Số điện thoại VN hợp lệ |
Response (200):
{
"success": true,
"message": "OTP đã được gửi lại"
}