Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Naxon's avatar
Level 6

Can't login after upload to Forge

Hi,

I started using Laravel Forge, got my site up and running real quick using quick deploy, also uploaded my database, and for some reason - I can't login to any user and no error is being displayed.

On my local machine the login works fine. The database connection is good.

Did this happen to anybody?

0 likes
19 replies
SaeedPrez's avatar

@Naxon check your .env file, in specific the APP_KEY so it's the same as in your local environment.

Naxon's avatar
Level 6

Also, my bad - I don't get any error message when typing any kind of username or password (right or wrong). APP_ENV is set to local and APP_DEBUG is set to true. But when I query the database - I do get results.

SaeedPrez's avatar

Hm, if you're not getting any error messages it might be because of session issues.. If you're using file session driver make sure your session folder has the correct owner and permissions.

Also wouldn't hurt to run..

> php artisan cache:clear
> composer dump-autoload
Naxon's avatar
Level 6

Doesn't work... I changed the session driver to database. Works on local machine, not on forge.

SaeedPrez's avatar

Hm, what about other configurations like timezone, domain, etc that could cause problems?

Maybe even try make some simple tests, like save some session value in one route, try get it in another, see if that works.

Naxon's avatar
Level 6

Works perfectly... I flashed some data to the session and it works... Only thing that doesn't work on forge is the login :(

nate.a.johnson's avatar

Have you registered an account in the database that forge is managing?

SaeedPrez's avatar

@nate.a.johnson he mentioned in his OP that he had uploaded his database, so I assume he has the user data in place.

So session is working, config is correct (including APP_KEY, domain, etc), database and data is there..

Do you have any custom middleware or have you made changes to the default authentication code?

Naxon's avatar
Level 6

@SaeedPrez I changed from email auth to username auth, but as I mentioned before, It works fine on my local machine.

LoginController.php

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide this functionality to your appliations.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login / registration.
     *
     * @var string
     */
    protected $redirectTo = '/members';

    protected $username = 'username';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'logout']);
    }
}

AuthenticatesUsers.php

<?php

namespace Illuminate\Foundation\Auth;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Lang;

trait AuthenticatesUsers
{
    use RedirectsUsers, ThrottlesLogins;

    /**
     * Show the application's login form.
     *
     * @return \Illuminate\Http\Response
     */
    public function showLoginForm()
    {
        return view('auth.login');
    }

    /**
     * Handle a login request to the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function login(Request $request)
    {
        $this->validateLogin($request);

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        if ($lockedOut = $this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        $credentials = $this->credentials($request);

        if ($this->guard()->attempt($credentials, $request->has('remember'))) {
            return $this->sendLoginResponse($request);
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        if (! $lockedOut) {
            $this->incrementLoginAttempts($request);
        }

        return $this->sendFailedLoginResponse($request);
    }

    /**
     * Validate the user login request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return void
     */
    protected function validateLogin(Request $request)
    {
        $this->validate($request, [
            $this->username() => 'required', 'password' => 'required',
        ]);
    }

    /**
     * Get the needed authorization credentials from the request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    protected function credentials(Request $request)
    {
        return $request->only($this->username(), 'password');
    }

    /**
     * Send the response after the user was authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    protected function sendLoginResponse(Request $request)
    {
        $request->session()->regenerate();

        $this->clearLoginAttempts($request);

        return $this->authenticated($request, $this->guard()->user())
                ?: redirect()->intended($this->redirectPath());
    }

    /**
     * The user has been authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  mixed  $user
     * @return mixed
     */
    protected function authenticated(Request $request, $user)
    {
        //
    }

    /**
     * Get the failed login response instance.
     *
     * @param \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    protected function sendFailedLoginResponse(Request $request)
    {
        return redirect()->back()
            ->withInput($request->only($this->username(), 'remember'))
            ->withErrors([
                $this->username() => Lang::get('auth.failed'),
            ]);
    }

    /**
     * Get the login username to be used by the controller.
     *
     * @return string
     */
    public function username()
    {
        return 'username';
    }

    /**
     * Log the user out of the application.
     *
     * @param  Request  $request
     * @return \Illuminate\Http\Response
     */
    public function logout(Request $request)
    {
        $this->guard()->logout();

        $request->session()->flush();

        $request->session()->regenerate();

        return redirect('/login');
    }

    /**
     * Get the guard to be used during authentication.
     *
     * @return \Illuminate\Contracts\Auth\StatefulGuard
     */
    protected function guard()
    {
        return Auth::guard();
    }
}
SaeedPrez's avatar

@Naxon why did you post AuthenticatesUsers trait, did you make changes to that as well?

Naxon's avatar
Level 6
    public function username()
    {
        return 'username';
    }

before the change it was hard-coded with:

    public function username()
    {
        return 'email';
    }
SaeedPrez's avatar

That might be what is causing it because you're not supposed to change anything in the vendor directory, it will be overwritten.

SaeedPrez's avatar

Since it's a trait, you can simply overwrite the function in your LoginController class..

    public function username()
    {
        return 'username';
    }
Naxon's avatar
Level 6

Well, I don't have the vendor directory on my server (it's on the default .gitignore)...

SaeedPrez's avatar
Level 50

Try adding the username() method to your LoginController and see if that works.

2 likes
SaeedPrez's avatar

Well, I don't have the vendor directory on my server (it's on the default .gitignore)...

It's on the .gitignore but when you deploy your website on Forge, it will run composer install and it will download a fresh copy of all your dependencies, which is why if you make changes to any files in your local vendor directory, they will not be applied to your production environment.

1 like

Please or to participate in this conversation.