Call go method in hooks

Is possible call the go method inside a hook?

I’m trying to do this:

'user.login:after' => function ($user, $session) {
    if ($user->role() == 'someRole') {
        go(site()->url() . '/panel/somepage');

but the next exception is showed on login: "Invalid login”

I assume it is because the panel is waiting for a different type of response to make the redirect to /site, but is there any way to make a redirect here?

Have you tried using the panelUrl() rather than site()->url?

I think you can pass it '/panel/somepage' to go somewhere specific.

Might just work if u swap out site()->url() for $user->panelUrl() in your code above. I dont think you will ‘/panel/’ in the bit you are concatinating. The panelUrl() should give you that much.

Thank you for the suggestion!

I tried, but I’m getting the same error.
EDIT: I’m getting “Invalid login” error

The problem is that the panel is waiting for a response in json format, and instead it is receiving an html which is the page I am trying to redirect to.
It looks like the redirection has to be done from the front-end.

The panel is Vue powered. That could be why. I think all the routing stuff is done through Vue, but you would need somone like @texnixe or @bastianallgeier or @lukasbestle or @distantnative to confirm that.

1 Like

It is not possible to redirect from hooks.

1 Like

Thank you for confirm that. @texnixe

You can load blue prints based on role, so even though they all login to the same place, you can lay that one page out diffrently based on role, so you can make a dashboard relevent to each role. That might be an option for you. At least the first page they see will have the bits most relevant to their role and they can just jump into it.

1 Like

I had already considered that approach, and I think it might be best for now, thank you very much!

If what you want to achieve is to limit what users can see, there are different ways to approach that, depending on your purpose. What @jimbobrjames described is one way to achieve something like that. Other options include page models route before hooks that prevent accessing certain panel pages.

1 Like

Thank you!