freekmurze / freek-dev-comments

2 stars 0 forks source link

695-a-laravel-package-to-impersonate-users #128

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

A Laravel package to impersonate users - Freek Van der Herten's blog on PHP, Laravel and JavaScript

https://freek.dev/695-a-laravel-package-to-impersonate-users

core45 commented 2 years ago

Looks like this package doesn't work correctly with Jetstream. Freek - did you test it with Jetstream/Sanctum maybe?

freekmurze commented 2 years ago

No, Jetstream / Sanctum didn't exist in 2017.

onlime commented 2 years ago

@core45 please describe the problem in a bit more detail. I'd like to know what does not work before I dig into it. Will try it out on a Jetstream Inertia+Vue stack project.

onlime commented 2 years ago

@core45 it so far works great on my Laravel 9 Jetstream project!

onlime commented 2 years ago

Ok, you were right @core45, laravel-impersonate didn't play nicely together with Jetstream. I have only tested on Laravel v9.3.1, but since having upgraded to v9.5.1, I experienced the same issues. @luigel has posted a workaround here:

https://github.com/404labfr/laravel-impersonate/issues/154#issuecomment-1068650950

e.g. in web.php:

//Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
Route::middleware(['auth:web', 'verified'])->get('/dashboard', function () {
    return Inertia::render('Dashboard');
})->name('dashboard');

so, AFAIK, laravel-impersonate currently only works on standard auth middleware and accessing some route behind Sanctum middleware would cause the user's session to be logged out.

core45 commented 2 years ago

Unfortunately I must use Laravel 8. And this solution with auth:web does not work. So I'm leaving it until I'm able to upgrade to 9