The Authentication With JWT module is a pre-built and maintained module that provides all the necessary functionality for user authentication in a Laravel project. The module includes features such as user registration, login, logout, forgot password, change password, and authentication logging. By using this module, developers can save time and effort in implementing these common authentication features in their projects, while promoting consistency and standardization in module design and implementation.
Laravel freamwork -nWidart/laravel-modules package, Implementing JWT authentication, php 7.2 or higher
Step 1: Install Module Package Library
composer require nwidart/laravel-modules{
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}
}
}if don't have Modules folder on laravel root then create manually.
git clone https://github.com/Hestabit/AuthWithJWT.gitcomposer require tymon/jwt-authFor installation and setup jwt read documents
'jwt.verify' => \Modules\AuthWithJWT\Http\Middleware\JWTMiddleware::class,
'jwt.auth' => 'Tymon\JWTAuth\Middleware\GetUserFromToken',
'jwt.refresh' => 'Tymon\JWTAuth\Middleware\RefreshToken',- Register
- Login
- Logout
- Fetch User Profile
- Update User Profile
- Forget Password
- Change Password
- Audit Logs
URL:- /api/register
Method:- POSTRequest Body:-
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Name of the user |
| Yes | Email of the user | ||
| password | string | Yes | Password of the user |
| password_confirmation | string | Yes | Confirm Pasword |
URL:- api/login
Method:- POSTRequest Body:-
| Parameter | Type | Required | Description |
|---|---|---|---|
| Yes | Email of the user | ||
| password | string | Yes | Password of the user |
URL:- api/logout
Method:- GETRequest Body:-
| Parameter | Type | Required | Description |
|---|---|---|---|
| token | string | Yes | JWT Token |
URL:- api/user_profile
Method:- GETRequest Body:-
| Parameter | Type | Required | Description |
|---|---|---|---|
| token | string | Yes | JWT Token |
URL:- api/udpate_user_profile
Method:- PUTRequest Body:-
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Name of the user |
| Yes | Email of the user | ||
| token | string | Yes | JWT Token |
URL:- api/forgot-password
Method:- POSTRequest Body:- email (email,required)
| Parameter | Type | Required | Description |
|---|---|---|---|
| Yes | Email of the user |
URL:- api/change-password
Method:- POSTold_password (required,string,min:6), password (required,string,min:6), password_confirmation (same as password)
Request Body:-
| Parameter | Type | Required | Description |
|---|---|---|---|
| old_password | string | Yes | Old password of the user |
| password | string | Yes | Password of the user |
| password_confirmation | string | Yes | Confirm Pasword |
| token | string | Yes | JWT Token |
URL:- api/user-logs
Method:- POSTRequest Body:-
| Parameter | Type | Required | Description |
|---|---|---|---|
| token | string | Yes | JWT Token |
php artisan test Modules/AuthWithJWT/Tests/Unit/ApiControllerTest.php