In this episode, we tackle a common but a bit tricky part of customizing Laravel Fortify: password confirmation. This feature is especially needed when we're about to set up two-factor authentication later on. For now, though, we want the dashboard to prompt users for their password—using a modal—before letting them in.
We start by applying the built-in password.confirm
middleware to the dashboard route and, as expected, things don't work straight away. Since we've disabled standard Laravel views (to use something like Inertia on the front end), Laravel can't find the right view to show, so we get a confusing error. The solution requires us to hook into the Fortify configuration and tell it what view (or in our case, Inertia page/modal) to use for password confirmations.
After a bit of source diving and route fixing (since disabling views in Fortify actually disables some routes as well), we break Fortify's usual behavior a bit by creating our own custom route and controller for password confirmation. Then, we set up our own modal component (using something like momentum-modal with Inertia) to pop up when users try to access the dashboard. The modal gets rendered just like any other Inertia modal would.
By the end of the video, we have a functional password confirmation modal showing up when it's supposed to. Next time, we'll work on fleshing out the form so users can actually submit their password and confirm access to the dashboard!