Laravel: Reset Password From an API

By | April 27, 2018

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 Illuminate\Foundation\Auth\SendsPasswordResetEmails 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!

6 thoughts on “Laravel: Reset Password From an API

  1. Lucas'

    In the route action i had to add ‘Api\Auth’ before the ‘ForgotPasswordController’. Thanks!

    Reply
  2. jogchicken

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

    Reply
  3. Luis

    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.

    Reply
  4. Venkatesh Rao P

    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 ??

    Reply

Leave a Reply

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

ten − 4 =