Redirect user based on group after Craft login I have a plugin that checks for the current user on login and should redirect the user if they are part of a particular user group. When I do this I get the following "An unknown error occurred." and the redirect doesn't work. See init function below:

function init()
{
    craft()-&gt;on( 'userSession.onLogin', function( Event $event ){
        $user = craft()-&gt;userSession-&gt;getUser();
        if ($user &amp;&amp; $user-&gt;isInGroup('sales')){
          $url = "new.url";
          craft()-&gt;request-&gt;redirect($url);
        }
    });
}


Please advise.
This is an alternate solution to what you're trying to do, and only applies if the login is coming and being directed to front end templates, but you could do something similar directly in your twig template, rather than having to use a plugin.

You could put something like...

{% if currentUser and currentUser.isInGroup('sales') %}
{% redirect "new.url" %}
{% endif %}


...somewhere on the page that logged in users will land on by default.