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

vmitchell85's avatar

Impersonation - Session Expired

When I impersonate another user and click on 'Home' I get the following error: Your session has expired. Please login again to continue.

Anyone had this issue? Are there certain things you can't have your application use and not break impersonation?

Thanks in advance!

0 likes
4 replies
zanematthew's avatar

Are there custom routes set? Or any custom middleware? I've ran into issues similar.

usama.ashraf's avatar

@vmitchell85 did you explicitly log out the first user ?

Also, Laravel doesn't use native PHP sessions, if that's relevant.

vmitchell85's avatar

@zanematthew - No custom middleware, just the default auth and subscribed in the HomeController

I am using Auth::user() in my blade template though... not using Vue for the data... could that be part of the issue?

@usama.ashraf - As I mentioned I'm using the Impersonation feature in Spark... I didn't log out of the dev user.

zanematthew's avatar

I was having a similar issue, granted I didn't document "what" the fix was, rather I just tried a bunch of things, and eventually it started working.

I did have auth set in my controller's __construct, but then later moved all that to the routes.php. I did this based on sample code in Spark/Laravel, figured that approach was to better organize the code.

My routes file looks like:

// Any page that should require authorization.
$router->group(['middleware' => ['auth']], function ($router) {

    $router->get('/home', 'ProductsController@show');
    $router->get('/dashboard', 'ProductsController@show');
    $router->get('/products/download/{key}', 'ProductsController@getDownloadUrl');

});

// Pages that do not require authorization
$router->group(['middleware' => ['web']], function ($router) {

    $router->get('/', 'WelcomeController@show');
    $router->get('/{page}', 'MarkdownPageController@show');

});

Note, I had moved any auth code from my controller, into my routes file, as above.

Please or to participate in this conversation.