Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impersonate From Within App #73

Open
MannikJ opened this issue Oct 23, 2020 · 4 comments
Open

Impersonate From Within App #73

MannikJ opened this issue Oct 23, 2020 · 4 comments

Comments

@MannikJ
Copy link

MannikJ commented Oct 23, 2020

Thank you for this great package. We use it all the time ;)
But now I would like to add some impersonation shortcuts directly to our app, because we often need to impersonate as the same user.
And I wonder what's the best way to do this.
I know this package is a nova package, so this isn't a use case its made for.
But I had quite a hard time understanding how this behaves in conjunction with the underlying 404labfr/laravel-impersonate package.

However I have come to an almost satisfying result:

  • added the default routes of the underlying package via Route::impersonate()
  • added a link to the take route

This way I can impersonate via the link and I am redirected to the app as the impersonated user with the reverse panel displayed exactly like it would behave if I had impersonated through nova.

But the problem lies in the detail. I would like to use the reverse panel and redirect to the same page, or at least the app home instead of nova. But since my link uses the other controller route, the redirect session cookie is not properly set.

How could I do that?

I guess this is related to #63 (comment), because if I could just use the nova-impersonate routes everything should work fine.

@MannikJ MannikJ changed the title Call Impersonate From Within App Impersonate From Within App Oct 23, 2020
@KABBOUCHI
Copy link
Owner

I'm not sure what exactly the issue, can you create a github repo?

@MannikJ
Copy link
Author

MannikJ commented Oct 23, 2020

Well I don't think it's necessary.

I just want to use the impersonate routes of this package manually from my app instead of from within nova.

Maybe I have just overseen something, as couldn't find how to call the routes.

@KABBOUCHI
Copy link
Owner

KABBOUCHI commented Oct 23, 2020

The routes protected by nova middleware, you can only use them if you are logged in in nova.

You can re-use the controller if you want https://github.com/KABBOUCHI/nova-impersonate/blob/master/src/Http/Controllers/ImpersonateController.php

or you can do ur own logic:

$manager = app('impersonate');

// Check if Impersonating
$manager->isImpersonating()

// Impersonate
$manager->take(auth()->user(), $user_to_impersonate);

// Leave 
$manager->leave()

@MannikJ
Copy link
Author

MannikJ commented Oct 26, 2020

Thank you! I am still wondering if there is a built-in way to register the routes, but it doesn't matter that much anyway. I just created my own routes and used your controller, which works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants