Password reset link token not including port in Laravel

891 Views Asked by At

I have an application with multiple authentication systems. There is one system which is made using the make:auth command and four others I've made manually. Everything works except for the Password reset link that is emailed to users when resetting a password using the authentication system I made with the make:auth command.

I have isolated the issue and found that the token being sent does not include the port. Therefore, when the user clicks on the reset password button received in their email, they get an error saying 'Object not found'. If I add the port to the URL, then it works.

I went to the .env file and modified APP_URL to add the port like so:

APP_URL=http://localhost:8000

This did not solve the issue.

I have made no modifications to the 'Illuminate\Foundation\Auth\SendsPasswordResetEmails.php' file. The function triggering in this file is:

    public function sendResetLinkEmail(Request $request)
{
    $this->validateEmail($request);

    // We will send the password reset link to this user. Once we have attempted
    // to send the link, we will examine the response then see the message we
    // need to show to the user. Finally, we'll send out a proper response.
    $response = $this->broker()->sendResetLink(
        $this->credentials($request)
    );

    return $response == Password::RESET_LINK_SENT
                ? $this->sendResetLinkResponse($request, $response)
                : $this->sendResetLinkFailedResponse($request, $response);
}
1

There are 1 best solutions below

2
On

Laravel hits ResetPassword class at vendor\laravel\framework\src\Illuminate\Auth\Notifications\ResetPassword from where it sends email with password reset link.

  public function toMail($notifiable)
    {
        if (static::$toMailCallback) {
            return call_user_func(static::$toMailCallback, $notifiable, $this->token);
        }

        return (new MailMessage)
            ->subject(Lang::getFromJson('Reset Password Notification'))
            ->line(Lang::getFromJson('You are receiving this email because we received a password reset request for your account.'))
            ->action(Lang::getFromJson('Reset Password'), url(config('app.url').route('password.reset', ['token' => $this->token, 'email' => $notifiable->getEmailForPasswordReset()], false)))
            ->line(Lang::getFromJson('This password reset link will expire in :count minutes.', ['count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]))
            ->line(Lang::getFromJson('If you did not request a password reset, no further action is required.'));
    }

In this function url(config('app.url'). this code get url (config/app.php) from app file in config folder. it auto set as localhost as base url.