# `POST` /api/users ## API 功能 user 註冊功能。 * 確認 name 是否超過 50 字。 * 確認 account 是否和其他 user 重複,如果重複則提示錯誤訊息。 * 確認 email 是否和其他 user 重複,如果重複則提示錯誤訊息。 * 確認 password 和 checkPassword 是否相同。 ## 前端傳入資料 ### parameters None ### req.body |Column|Description| |------|-----------| |name|使用者名稱(50 字以內)| |account|登入帳號| |email|email| |password|登入密碼| |passwordCheck| 確認密碼(需與登入密碼相同)| ## 後端回傳資料 ### 註冊成功 ```json // status code: 200 { "status": "success", "message": "Sign up success." } ``` ### 傳入資料格式有誤 發生原因: 檢查後發現任一欄位為空或短少欄位。 ```json // status code: 400 { "status": "error", "message": "All fields are required." } ``` 發生原因: `name` 欄位超過 50 字元。 ```json // status code: 400 { "status": "error", "message": "Field 'name' should be limited within 50 characters." } ``` ### 驗證失敗 發生原因: password 和 passwordCheck 不同。。 ```json // status code: 401 { "status": "error", "message": "Password and checkPassword should be the same." } ``` 發生原因: account 或 email 重複。 ```json // status code: 401 // account 重複 { "status": "error", "message": "Account already exists. Please try another one." } // email 重複 { "status": "error", "message": "Email already exists. Please try another one." } ``` ## 相關連結 * [回首頁](https://hackmd.io/@twitter-2022/index) * [API 總表](/Gl56cI2LQ5ObBpmQnbnphw) ###### tags: `API-doc`