coolcode / authapi
api authentication using sanctum
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:package
pkg:composer/coolcode/authapi
Requires
- laravel/sanctum: 4.x-dev
README
coolcode/authapi is a Laravel package that simplifies API authentication using Laravel Sanctum. This package provides a set of endpoints for user registration, login, and logout functionality with token-based authentication.
Installation
-
Install the package via Composer:
composer require coolcode/authapi
-
Publish the Sanctum migrations:
php artisan vendor:publish --tag=sanctum-migrations
-
Run the migrations:
php artisan migrate
-
Finally, issue your Laravel Sanctum tokens when users authenticate with your API.
API Endpoints
1. Register
Endpoint: /api/register
Method: POST
Headers:
Accept: application/jsonContent-Type: application/json
Request Body (form-data):
| Key | Value | Type |
|---|---|---|
| name | test | text |
| test@gmail.com | text | |
| password | password | text |
| confirm_password | password | text |
Description:
Registers a new user in the system.
2. Login
Endpoint: /api/login
Method: POST
Headers:
Accept: application/jsonContent-Type: application/json
Request Body (form-data):
| Key | Value | Type |
|---|---|---|
| test@gmail.com | text | |
| password | password | text |
Description:
Authenticates the user and issues a Bearer token for future API requests. The token is stored in the environment variable token.
3. Logout
Endpoint: /api/logout
Method: POST
Headers:
Accept: application/jsonContent-Type: application/jsonAuthorization: Bearer {{token}}
Description:
Logs the authenticated user out and invalidates the Bearer token.
Usage
Once you've installed the package and set it up, you can use these endpoints in your Postman collection or any API client to handle user authentication.
Postman Example
- Register a user using the Register API.
- Login using the Login API to get the Bearer token.
- Set the token in your environment variables for future authenticated requests.
- Logout the user using the Logout API.
License
This package is open-sourced software licensed under the MIT license.