stephen1204paul's avatar

Password reset link is pointing to old APP_URL

I changed the APP_URL from test domain extension to IP Address. But the password reset email is showing link with the previous APP_URL as the base url.

The following are steps that I have tried to solve this:

  1. Change APP_URL in .env file
  2. Change url in config/app.php to the ip address instead of env variable.
  3. Ran php artisan config:clear
  4. Ran php artisan cache:clear

How can I solve this?

0 likes
10 replies
frankielee's avatar

Run php artisan optimize:clear to clear all the caches

stephen1204paul's avatar

Didn't work as well. It is still send link pointing to the test extension domain

frankielee's avatar

Have you tried to echo the value in tinker?

PHP artisan tinker
env('APP_URL')
stephen1204paul's avatar

The image is here. https://imgur.com/uMpKAkN.

My broadcast driver is set to log. So I think queue is not the problem. Plus I do receive the email just that the base url in link is not updated

frankielee's avatar
Level 29

Hi, are you changing the APP_URL at local?

From the codes, vendor/laravel/framework/src/illuminate/Notifications/ResetPassword.php

The URL generated is using the helper route() which basically current appending the current domain with the URL defined in the web.php

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

        if (static::$createUrlCallback) {
            $url = call_user_func(static::$createUrlCallback, $notifiable, $this->token);
        } else {
            $url = url(route('password.reset', [
                'token' => $this->token,
                'email' => $notifiable->getEmailForPasswordReset(),
            ], false));
        }

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

frankielee's avatar

Example: Your current domain is http://localhost:8000,

web.php

Route::get('reset','ResetController@test')->name('test');

route('test') will return http://localhost:8000/reset
stephen1204paul's avatar

Yes I am trying this in local.

So the base url in reset password link will always follow the domain and not the APP_URL or url?

Please or to participate in this conversation.