# `POST` /api/admin/signin ## API 功能 身分驗證,通過驗證將回傳登入者資料及 token。 * 確認登入帳號及密碼正確。 * 確認登入者是否為 Admin。 * 回傳身分驗證 token 及登入 Admin 資料。 ## 前端傳入資料 ### parameters None ### req.body | name | description | required | | ---------- | ----------- | -------- | | `account` | account | true | | `password` | password | true | ## 後端回傳資料 ### 驗證成功 ```javascript // status code: 200 { "token": "random token", "user": { "id": 1, "account": "root", "email": "root@example.com", "name": "root", "avatar": "<url>", "cover": "<url>", "introduction": "text content", "role": "admin", "createdAt": "2022-07-29T22:00:00.000Z", "updatedAt": "2022-07-29T22:00:00.000Z" } } ``` ### 傳入資料格式有誤 發生原因: 檢查後發現任一欄位為空。 ```json // status code: 400 { "status": "error", "message": "All fields are required." } ``` ### 驗證失敗 使用 user 帳號登入或帳號還沒註冊過 ```json // status code: 401 { "status": "error", "message": "Account not exists for admin." } ``` 密碼錯誤 ```json // status code: 401 { "status": "error", "message": "Password incorrect." } ``` ## 相關連結 * [回首頁](https://hackmd.io/@twitter-2022/index) * [API 總表](/Gl56cI2LQ5ObBpmQnbnphw) ###### tags: `API-doc`