0

I'm trying to make alive again an old project using Laravel 5.4 and Laravel Valet.

I'm facing an issue with authentication.

LoginController

public function authenticated(Request $request, User $user){
        $previous_session = $user->session_id;
        if ($previous_session) {
            Session::getHandler()->destroy($previous_session);
        }
        $user = Auth::user();
        $user->session_id = Session::getId();
        $user->save();
        Auth::login($user, true);
        return redirect('testlogin');
    }

Routes

Route::get('testlogin', function () {
    dd(\Illuminate\Support\Facades\Auth::check());
});

In the LoginController, $user is retrieved and not null, but as soon as a redirection is made Auth::check() is false

Questions

What's wrong ? I cannot make make up my mind on this

1
  • Can you provide more console logs or debug infos? Commented May 15, 2019 at 3:08

2 Answers 2

1

This drove me crazy a few times as well. Most likely your 'testLogin' route is not contained within the auth middleware, which would not give you auth at the time of the route passing. If this is the case, move your 'testLogin' route inside the following:

Route::group(['middleware' => ['auth']], function () { ... HERE ... }
Sign up to request clarification or add additional context in comments.

1 Comment

It is not under auth middleware, but now I cannot access the route at all. Because specifically of the auth middleware I think
0

In the .env file, the variable SESSION_DOMAIN was not set properly and did not reflect the local domain (which had changed between now and few years ago)... Stupid error but I hope it might prevent others to do the same.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.