josegus/laravel-quick-login

Quick auth & login


Keywords
Authentication, login, laravel, impersonate, laravel-quick-login
License
MIT

Documentation

Laravel Quick Login

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A simple Laravel component that enables quick login functionality for development environments.

In short, it includes a blade component that you can include in your login view to:

  • create new users and automatically log in as the created user, with one click
  • select an existing user to log in, with one click

Installation

You can install the package via composer:

composer require josegus/laravel-quick-login

You can publish the config file with:

php artisan vendor:publish --tag="quick-login-config"

This will create the config/quick-login.php file with the following options:

return [
    'model' => \App\Models\User::class,

    'displayed_attribute' => 'email',

    'redirect_to' => env('QUICK_LOGIN_REDIRECT_TO', 'dashboard'),
];

Optionally, you can publish the views using

php artisan vendor:publish --tag="quick-login-views"

Usage

Blade Component

The package includes a Blade component that you can use in any view:

<x-josegus::quick-login-form />

The above code will use Laravel's default authentication model (App\Models\User) and guard (web).

Using a different guard

If your app uses a different guard, pass it as a parameter to the component:

<x-josegus::quick-login-form guard="customer" />

Using factory states

To create new users, the package will use the factory defined in your auth model, so make sure your auth model uses the HasFactory trait. You can pass an array of factory states that will be applied when the package creates new users:

<x-josegus::quick-login-form
    :factory-states="['isForeign', 'withCompany']"
/>

Using extra model attributes

Alternatively, you can pass an array of properties that will be applied when the package creates new users:

<x-josegus::quick-login-form
    :model-attributes="['is_foreign' => true, 'company_name' => 'Laravel']"
/>

Advanced Customization

Change the Displayed Attribute

By default, the user's email is displayed. You can change this in the configuration:

// config/quick-login.php
return [
    'displayed_attribute' => 'username',
];

Testing

composer test

License

This package is open-source software licensed under the MIT license.

Security

⚠️ Warning: This package is designed for development environments only. It is not recommended for use in production.