Skip to content

Add Laravel Authentication Event Support #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 1, 2025
Merged

Conversation

nycomar
Copy link
Contributor

@nycomar nycomar commented Mar 29, 2025

This PR aligns the DevDojo Auth component with Laravel's native authentication event system by dispatching:

  • Illuminate\Auth\Events\Attempting
  • Illuminate\Auth\Events\Failed

🔧 Changes

  1. Event Dispatching
    Added event triggers in login.blade.php:

    // Authentication attempt started
    event(new Attempting('web', $credentials, $remember));
    
    // Failed authentication
    event(new Failed('web', $user, $credentials));
  2. Backwards Compatibility
    Maintains existing functionality while enabling event-driven extensions:

    // Existing code remains unchanged
    if (!Auth::validate($credentials)) {
        // Original error handling preserved
        $this->addError('password', trans('auth.failed'));
    }

➕ Benefits

  • Enables standard Laravel auth extensions:
    • Login auditing
    • Rate limiting
    • IP blocking
  • Zero breaking changes
  • Minimal performance impact (events only fire when listeners exist)

🏷 Versioning

Recommend minor version bump to `1.1.0 per semver (non-breaking feature addition)

🛠 Maintenance Notes

  1. Events use Laravel's native classes
  2. No new dependencies introduced
  3. Fully testable via existing Laravel event testing utilities

Consider adding following to docs:.

Event Hooks

The component now fires standard Laravel authentication events:

Event When Data Included
Attempting Credentials validation starts Email, Password, Remember
Failed Invalid login attempt User model (if found)
Login Successful authentication Authenticated user

Example Listener:

Event::listen(Failed::class, function ($event) {
    Log::warning('Failed login attempt', [
        'email' => $event->credentials['email'],
        'ip' => request()->ip()
    ]);
});

Copy link
Contributor

@bobbyiliev bobbyiliev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This looks good to me, but also tagging @tnylea for a review!

@tnylea
Copy link
Contributor

tnylea commented Apr 1, 2025

Looks great. Thanks @nycomar

@tnylea tnylea merged commit 7d77223 into thedevdojo:main Apr 1, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants