Session lost on Laravel Dusk using Laravel Sail

78 views Asked by At

I'm using Laravel Sail to run a small Laravel project. I would like to add some Dusk tests to it but I'm stuck on a problem which I believe is related to the session being lost.

All tests that don't require authentication work, however, when I try to manually authenticate a user inside of the test and then dd it, it returns null.

This is my code:

        $this->browse(function (Browser $browser) {
            $browser->loginAs(User::find(1));
            dd(auth()->user()); <--- null is returned here
             
            // if i try to access any login protected page here
            // it redirects me to the login page
        });

I didn't change the default .env file so there are no custom configuration settings and I've followed the steps showed in the documentation to setup dusk with sail (https://laravel.com/docs/10.x/sail#laravel-dusk).

Any idea what the problem could be?

0

There are 0 answers