https://github.com/kublahanov/jwt-auth-template-server-laravel-10
Template for REST API with JWT-auth based on Laravel 10.
https://github.com/kublahanov/jwt-auth-template-server-laravel-10
jwt-auth-template laravel10
Last synced: 3 months ago
JSON representation
Template for REST API with JWT-auth based on Laravel 10.
- Host: GitHub
- URL: https://github.com/kublahanov/jwt-auth-template-server-laravel-10
- Owner: kublahanov
- License: mit
- Created: 2024-06-13T17:16:05.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-01-31T19:47:47.000Z (4 months ago)
- Last Synced: 2025-01-31T20:33:09.205Z (4 months ago)
- Topics: jwt-auth-template, laravel10
- Language: PHP
- Homepage:
- Size: 404 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# JWT-auth REST API (server) template based on Laravel 10

This project is an extended version of the Laravel 10 source code designed to provide a template for JWT
authentication-based REST API server applications with a full user authentication cycle.## About the Project
This is a starter template for developing REST API applications using Laravel 10 and JWT-auth.
**It includes:**
- A clean REST API implementation.
- Client JWT authentication with all necessary options: authentication with getting bearer token, token refreshing, etc.
- User authentication, including: registration (with email verification), authentication (login and logout), password
changing, and so on.## Getting Started
These instructions will help you clone and run the project on your local machine for development and testing purposes.
### Prerequisites
Necessary:
- [git](https://git-scm.com/)
- [php8+](https://www.php.net/downloads)
- [composer](https://getcomposer.org/download/)Optional:
- [docker](https://docs.docker.com/engine/install/)
If not using [Laravel Sail](https://laravel.com/docs/10.x/sail):
- MySQL or another supported database.
### One-step installation
Run this shell script in the root of the project:
`./setup.sh`
### Manually installation
1. Clone the repository:
```bash
git clone https://github.com/kublahanov/laravel-10-template.git
cd laravel-10-template
```2. Install dependencies via Composer:
```bash
composer install
```3. Copy the `.env.example` file to `.env` (if it not completed automatically in step 2):
```bash
cp .env.example .env
```4. Generate the application key (if it not completed automatically in step 2):
```bash
php artisan key:generate
```5. Configure your database settings in the `.env` file.
6. Run the database migrations:
```bash
php artisan migrate
```7. Start the local development server (or use [Laravel Sail](https://laravel.com/docs/10.x/sail)):
```bash
php artisan serve
```Your application should now be accessible at `http://localhost:8000`.
### Features
- **JWT Authentication**: Implemented using the `tymon/jwt-auth` package.
- **REST API**: All routes and controllers for auth-based API.### Usage Examples
#### User Registration
`POST /api/auth/register`
```json
{
"name": "John Doe",
"email": "[email protected]",
"password": "password",
"password_confirmation": "password"
}
```Response:
```json
{
"message": "User registered successfully, please check your email for verification link",
"user": {
"name": "John Doe",
"email": "[email protected]",
"updated_at": "2024-06-26T18:03:49.000000Z",
"created_at": "2024-06-26T18:03:49.000000Z",
"id": 1
}
}
```#### User Login
`POST /api/auth/login`
```json
{
"email": "[email protected]",
"password": "password"
}
```Response:
```json
{
"access_token": "your-jwt-token",
"token_type": "bearer",
"expires_in": 3600
}
```### Deployment
For deploying on a production server, it is recommended to follow these steps:
1. Install all dependencies and run the migrations.
2. Configure your web server (e.g., Nginx or Apache) to work with Laravel.
3. Ensure you have the appropriate caching and session levels set up.### Contributing
If you have suggestions for improving this project or want to report a bug, please open
an [issue](https://github.com/kublahanov/laravel-10-jwt-auth-template/issues) or create a [pull
request](https://github.com/kublahanov/laravel-10-jwt-auth-template/pulls).### License
This project is licensed under the [MIT license](https://opensource.org/licenses/MIT).