Skip to content

kublahanov/jwt-auth-template-server-laravel-10

Repository files navigation

Laravel Logo JWT auth REST API

JWT-auth REST API (server) template based on Laravel 10

Laravel JWT Auth

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:

Optional:

If not using Laravel 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:

    git clone https://github.com/kublahanov/laravel-10-template.git
    cd laravel-10-template
  2. Install dependencies via Composer:

    composer install
  3. Copy the .env.example file to .env (if it not completed automatically in step 2):

    cp .env.example .env
  4. Generate the application key (if it not completed automatically in step 2):

    php artisan key:generate
  5. Configure your database settings in the .env file.

  6. Run the database migrations:

    php artisan migrate
  7. Start the local development server (or use Laravel Sail):

    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

{
  "name": "John Doe",
  "email": "john.doe@example.com",
  "password": "password",
  "password_confirmation": "password"
}

Response:

{
  "message": "User registered successfully, please check your email for verification link",
  "user": {
    "name": "John Doe",
    "email": "john.doe@example.com",
    "updated_at": "2024-06-26T18:03:49.000000Z",
    "created_at": "2024-06-26T18:03:49.000000Z",
    "id": 1
  }
}

User Login

POST /api/auth/login

{
  "email": "john.doe@example.com",
  "password": "password"
}

Response:

{
  "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 or create a pull request.

License

This project is licensed under the MIT license.

About

Template for REST API with JWT-auth based on Laravel 10.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published