Authentication

# Introduction

This set of components was designed to simplify the user authentication process in your Laravel application. The installation process is straightforward, allowing you to set up these essential features with just a few steps.

Once installed, all Livewire components and associated views will be stored directly within your application’s directory, giving you full control over the design and complete freedom to customize the look and feel according to your needs.

# Features

The authentication components include the following features:

  • Registration
  • Login
  • Password reset
  • Email verification

# Demo

# Installation

To make the installation process as smooth as possible, we’ve prepared a custom Artisan command that automates the setup of all necessary components.

Simply run the following command in your terminal to get started:

 
php artisan zinq:install:auth

You can also customize the installation process by excluding certain components:

  • To skip publishing components and views related to password reset, run the command with the --no-password flag,
  • To skip publishing components and views related to email verification, run the command with the --no-email-verification flag.

Once the installation is complete, the next step is to configure your application’s routing to ensure the authentication system works correctly.

# Login and registration

To set up the login and registration routes, add the following code to your routes/web.php file:

 
Route::group(['middleware' => 'guest'], function () {
    Route::get('/login', \App\Livewire\Auth\Login::class)
        ->name('login');

    Route::get('/login/{email}', \App\Livewire\Auth\LoginEmail::class)
        ->name('login-email')
        ->middleware('signed:relative');

    Route::get('/register', \App\Livewire\Auth\Register::class)
        ->name('register');
});

# Password reset

To set up the password reset routes, update the group with guest middleware in your routes/web.php file:

 
Route::group(['middleware' => 'guest'], function () {
    // ...

    Route::get('/forgot-password', \App\Livewire\Auth\ForgotPassword::class)
        ->name('password.request');

    Route::get('/reset-password/{token}/{email}', \App\Livewire\Auth\ResetPassword::class)
        ->name('password.reset');
});

# Email verification

The email verification functionality was built using Laravel’s built-in Email Verification.

It consists of the following parts:

  • Email verification notice page - a page that informs the user about the need to verify their email address,
  • Email verification route - a route that marks the user’s email address as verified.
  1. First step is to add email verification notice page. It will be displayed when the user tries to access a protected route without verifying their email address. To do this, add the following code to your routes/web.php file:
 
Route::group(['middleware' => ['auth']], function () {
    Route::get('/email/verify-notification', \App\Livewire\Auth\EmailVerificationNotice::class)
        ->name('verification.notice');

    Route::group(['middleware' => ['verified']], function () {
    
        // Your protected routes here...
        
    });
});
  1. Now you need to add the email verification route. To do this, add the following code to your routes/web.php file:
 
use Illuminate\Foundation\Auth\EmailVerificationRequest;

Route::group(['middleware' => ['auth:admin']], function () {

    // ...

    Route::get('/email/verify/{id}/{hash}', function (EmailVerificationRequest $request) {
            $request->fulfill();

            return redirect()->route('dashboard');
        })
        ->middleware('signed')
        ->name('verification.verify');

    // ...
    // 
});