From aef45866fbfb0f1adbb2b7c3d5c8d3d02423c69b Mon Sep 17 00:00:00 2001 From: "Jethro Lin (aider)" Date: Wed, 13 Nov 2024 12:49:34 +0800 Subject: [PATCH] docs: add instructions for obtaining admin token in API docs --- 16. `docs/api.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/16. `docs/api.md b/16. `docs/api.md index 8f92f60..a7f6779 100644 --- a/16. `docs/api.md +++ b/16. `docs/api.md @@ -11,6 +11,30 @@ ### POST /api/logout - **Description**: Logout the user and revoke the token. - **Response**: JSON object with a success message. +### Obtaining an Admin Token +- **Description**: To obtain a token for an admin user, follow these steps: + 1. **Ensure the Admin User Exists**: Make sure there is an admin user in the database. If not, create one using the following command: + ```bash + php artisan tinker + $user = new App\Models\User; + $user->name = 'Admin User'; + $user->email = 'admin@example.com'; + $user->password = bcrypt('password'); + $user->role = 'admin'; + $user->save(); + exit + ``` + 2. **Authenticate the Admin User**: Use the `/api/login` endpoint to authenticate the admin user and obtain the token. Send a POST request with the admin user's credentials: + ```bash + curl -X POST http://your-app-url/api/login -H "Content-Type: application/json" -d '{"email":"admin@example.com","password":"password"}' + ``` + 3. **Response**: The response will include a JSON object with the generated token: + ```json + { + "token": "your-generated-token" + } + ``` + ## Admin Management ### GET /api/admin/users