docs: add instructions for obtaining admin token in API docs

This commit is contained in:
Jethro Lin (aider) 2024-11-13 12:49:34 +08:00
parent e9be91876e
commit aef45866fb

View file

@ -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