Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Auth Laravel Package

dginxreal/laravel-auth

dginxreal/laravel-auth is a lightweight Laravel authentication package that helps you add common auth features to your app with minimal setup, providing a starting point for implementing login/session-based access control.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require dginxreal/laravel-auth
    php artisan vendor:publish --provider="Dginxreal\Auth\AuthServiceProvider" --tag="migrations"
    php artisan migrate
    
  2. Configuration Publish the config file:

    php artisan vendor:publish --provider="Dginxreal\Auth\AuthServiceProvider" --tag="config"
    

    Review config/auth.php for customization (e.g., guard names, user model).

  3. First Use Case Register a route in routes/web.php:

    use Dginxreal\Auth\Facades\Auth;
    
    Route::get('/login', function () {
        return Auth::attempt(['email' => 'user@example.com', 'password' => 'password']);
    });
    

Implementation Patterns

Core Workflows

  1. Authentication

    • Login/Logout:
      Auth::attempt($credentials); // Login
      Auth::logout(); // Logout
      
    • Session Handling:
      Auth::loginUsingId($userId); // Force login
      Auth::logoutOtherDevices($password); // Multi-device logout
      
  2. User Management

    • Registration:
      use Dginxreal\Auth\Facades\Auth;
      $user = Auth::register(['name' => 'John', 'email' => 'john@example.com', 'password' => 'secret']);
      
    • Password Reset:
      Auth::sendPasswordResetLink(['email' => 'user@example.com']);
      Auth::resetPassword($token, ['password' => 'newpassword']);
      
  3. Middleware Integration Use the package’s built-in middleware:

    Route::middleware(['auth:api'])->group(function () {
        // Protected API routes
    });
    

Integration Tips

  • Custom Guards: Extend the AuthServiceProvider to add custom guards:
    protected function guards()
    {
        return [
            'web' => ['driver' => 'session', 'provider' => 'users'],
            'admin' => ['driver' => 'session', 'provider' => 'admins'],
        ];
    }
    
  • Event Listeners: Listen to auth events (e.g., Attempting, Authenticated):
    Auth::listen(function ($event) {
        Log::info('Auth event: ' . $event->fires);
    });
    
  • API Tokens: Use Laravel Sanctum or Passport alongside the package for token-based auth.

Gotchas and Tips

Pitfalls

  1. Migration Conflicts

    • Ensure the package’s migrations don’t conflict with existing users table migrations. Run:
      php artisan vendor:publish --tag="migrations" --force
      
      Then manually resolve conflicts.
  2. Session Driver Mismatch

    • If using api guard, ensure SESSION_DRIVER in .env is set to database or redis for consistency.
  3. Password Hashing

    • The package uses Laravel’s default Hash facade. If customizing, ensure the users table’s password column uses the same hashing algorithm.

Debugging

  • Failed Logins: Check Auth::validate($credentials) for manual validation before attempt() to debug credential issues.
  • Session Issues: Clear cached config and sessions:
    php artisan config:clear
    php artisan cache:clear
    php artisan session:clear
    
  • Event Debugging: Use Auth::listen() to trace auth events in real-time.

Extension Points

  1. Custom User Model Override the default user model in config/auth.php:

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\CustomUser::class,
        ],
    ],
    
  2. Custom Auth Logic Extend the AuthManager class by binding a custom implementation in the service provider:

    $this->app->bind('auth', function ($app) {
        return new \App\Services\CustomAuthManager($app);
    });
    
  3. Rate Limiting Integrate with Laravel’s throttle middleware for login attempts:

    Route::post('/login', function () {
        return Auth::attempt(request()->only(['email', 'password']));
    })->middleware('throttle:5,1');
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor