Laravel

Laravel: Reset Password From an API

Assalamualaikum,

Today, will share about how to reset your account in Laravel application from an API.

This is assumed you already setup JWT Auth in your Laravel app.

Create a new API controller – php artisan make:controller Api/Auth/ForgotPasswordController and copy paste the following code, and add the forgot password route in routes/api.php.

So, basically what I did was to use IlluminateFoundationAuthSendsPasswordResetEmails trait, which being used in the default Laravel Forgot Password Controller.

I just copy codes from sendResetLinkEmail method, and make changes on how the response we should receive from an API.

Then you are done! Easy right? 🙂

To test, open up your email, you just need to pass email address – just like we did in Laravel Auth Scaffold, then you are done.

The email owner will receive reset password link, and the owner open up the email, click on the link, go reset as usual, as we did on web app.

That’s all, thanks!

11 thoughts on “Laravel: Reset Password From an API

  1. i have erro like this “InvalidArgumentException thrown with message "Route [password.reset] not defined."”

  2. Hi.
    When I try to use your code I get an error message that says “Route [password.reset] not defined.”
    I know I have to add that route in api.php but I do not know which controller and which method I have to point to.

  3. But once the user clicks on the password reset link there should be an form which accepts new passwords and an post api to save new password. Did you skip this part ??

  4. Not really. If you’ve seen how Laravel handles the reset password issue, you’d realize that Laravel first shows you a form where you must enter your email address then, if the email address exists Laravel sends you an email with a link where the form where you can reset your password is.
    Then in that second form you can reset your password, and at that time is when you can send your password you want to change.

Leave a Reply

Your email address will not be published. Required fields are marked *

thirteen + one =