In this episode, we look at how to let users set a password in your app, especially if they've signed up using social authentication (like GitHub or Twitter). By default, the user account created through social login won't have a password set, but you might still want to give users the option to set one, so they can log in the traditional way too.
We walk through the gotchas you might hit if your user table doesn't include a password, or if your forms still expect users to have an existing password. We tweak the logic so that users who don't have a password won't be required to enter their "current password" on the change password form, making the process as smooth as possible.
You'll see how to add a simple hasPassword
helper method to the user model, update Blade templates to hide or show form fields depending on whether the user has a password, and adjust the password controller to skip validation on the current password if it's not needed. Finally, we demo how a user can set a password for the first time, and then successfully use password login alongside their social authentication. It's a practical episode for anyone adding flexibility to the login system!