pato.llaguno
pato.llaguno

Reputation: 741

laravel app stops working when deployed to AWS

I have a laravel app that in my local machine works fine and when i deploy it to aws i get errors. The part i am getting errors is the following. My app has admin users which create new users, when the user is created an email is sent to them with a link and a token for them to pick their password. The problem is once they pick their password when the post is clicked I get the following error.

On my local machine php version is 7.2.3 windows. and AWS has 7.2.13 elastic beanstalk

Argument 2 passed to Illuminate\Auth\Passwords\PasswordBroker::__construct() must implement interface Illuminate\Contracts\Auth\UserProvider, null given, called in /var/app/current/vendor/laravel/framework/src/Illuminate/Auth/Passwords/PasswordBrokerManager.php on line 75

the relevant code for the post is the following:

public function reset(Request $request)
    {
        $request->validate($this->rules(), $this->validationErrorMessages());


        // Here we will attempt to reset the user's password. If it is successful we
        // will update the password on an actual user model and persist it to the
        // database. Otherwise we will parse the error and return the response.

        $response = $this->broker()->reset(
            $this->credentials($request), function ($user, $password) {
                $this->resetPassword($user, $password);
            }
        );

        // If the password was successfully reset, we will redirect the user back to
        // the application's home authenticated view. If there is an error we can
        // redirect them back to where they came from with their error message.
        return $response == Password::PASSWORD_RESET
                    ? $this->sendResetResponse($request, $response)
                    : $this->sendResetFailedResponse($request, $response);
    }
    protected function rules()
    {
        return [
            'token' => 'required',
            'email' => 'required|email',
            'password' => 'required|confirmed|min:8',
        ];
    }

    /**
     * Get the password reset validation error messages.
     *
     * @return array
     */
    protected function validationErrorMessages()
    {
        return [];
    }
    /**
     * Get the password reset credentials from the request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    protected function credentials(Request $request)
    {

        return $request->only(
            'email', 'password', 'password_confirmation', 'token'
        );
    }

    /**
     * Reset the given user's password.
     *
     * @param  \Illuminate\Contracts\Auth\CanResetPassword  $user
     * @param  string  $password
     * @return void
     */
    protected function resetPassword($user, $password)
    {
        $user->password = Hash::make($password);

        $user->setRememberToken(Str::random(60));

        $user->save();

        event(new PasswordReset($user));

        $this->guard()->login($user);
    }

    /**
     * Get the response for a successful password reset.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  string  $response
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
     */
    protected function sendResetResponse(Request $request, $response)
    {
        return redirect($this->redirectPath())
                            ->with('status', trans($response));
    }

    /**
     * Get the response for a failed password reset.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  string  $response
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
     */
    protected function sendResetFailedResponse(Request $request, $response)
    {
        return redirect()->back()
                    ->withInput($request->only('email'))
                    ->withErrors(['email' => trans($response)]);
    }

    /**
     * Get the broker to be used during password reset.
     *
     * @return \Illuminate\Contracts\Auth\PasswordBroker
     */
    public function broker()
    {
        return Password::broker('newusers');
    }

    /**
     * Get the guard to be used during password reset.
     *
     * @return \Illuminate\Contracts\Auth\StatefulGuard
     */
    protected function guard()
    {
        return Auth::guard();
    }

Upvotes: 0

Views: 205

Answers (1)

Leonardo Rossi
Leonardo Rossi

Reputation: 3022

Check your config auth.php files. The code raising the error is this

return new PasswordBroker(
    $this->createTokenRepository($config),
    $this->app['auth']->createUserProvider($config['provider'] ?? null)
);

The second parameter is giving null, maybe because there is a config missing?

Upvotes: 2

Related Questions