Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Nick-'s avatar

Jetstream/fortify redirect after enabling 2FA

I have a project where 2FA is mandatory, if a user has not setup 2FA and logs in or visits a page he/she will be redirected to /2fa to setup 2FA. After setting up 2FA I want the user to be redirected to the homepage/dashboard but instead the user is shown 2FA is enabled and that's it.

I have jestream installed with Livewire. As far as I can see there's no event fired with which I can do something.

0 likes
1 reply
LaryAI's avatar

Certainly! Here’s how you can handle redirecting the user to the dashboard (or any route) after they enable 2FA with Jetstream (Livewire):

Problem Recap

  • Users are forced to set up 2FA at /2fa.
  • After enabling 2FA, they remain on the same page instead of being redirected to the dashboard.

Solution

1. Listen for the 2FA Enabled Event in Livewire

Jetstream’s 2FA setup is handled by a Livewire component: Profile/TwoFactorAuthenticationForm.
When 2FA is enabled, it emits the two-factor-authentication-enabled event.

You can listen for this event in your Livewire component or in Alpine.js (if you use it).

Option 1: Alpine.js Redirect

Edit your /resources/views/profile/two-factor-authentication-form.blade.php (or wherever you show the 2FA form):

<div
    x-data
    x-on:two-factor-authentication-enabled.window="window.location = '{{ route('dashboard') }}'"
>
    @livewire('profile.two-factor-authentication-form')
</div>

This listens for the event and redirects to the dashboard.

Option 2: Livewire Redirect

If you want to handle it in Livewire, you can extend the Jetstream component:

  1. Publish Jetstream’s Livewire components (if you haven’t):

    php artisan vendor:publish --tag=jetstream-views
    
  2. Extend the TwoFactorAuthenticationForm Livewire component:

    In app/Http/Livewire/Profile/TwoFactorAuthenticationForm.php:

    namespace App\Http\Livewire\Profile;
    
    use Laravel\Jetstream\Http\Livewire\TwoFactorAuthenticationForm as JetstreamTwoFactorAuthenticationForm;
    
    class TwoFactorAuthenticationForm extends JetstreamTwoFactorAuthenticationForm
    {
        public function enableTwoFactorAuthentication()
        {
            parent::enableTwoFactorAuthentication();
    
            // After enabling, redirect
            return redirect()->route('dashboard');
        }
    }
    

    Then update your Blade view to use your custom component.


3. (Alternative) Use a Middleware

If you’re forcing users to /2fa until they set up 2FA, you might already have a middleware.
After enabling 2FA, the middleware will let them access the dashboard.


Summary

Quickest fix:
Add this around your Livewire component:

<div
    x-data
    x-on:two-factor-authentication-enabled.window="window.location = '{{ route('dashboard') }}'"
>
    @livewire('profile.two-factor-authentication-form')
</div>

This will redirect the user as soon as 2FA is enabled.

Let me know if you need help with a custom Livewire solution or middleware!

Please or to participate in this conversation.