Answers.Body: <p>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.</p>
  
  <p>You could put something like...</p>
  
  <pre><code>{% if currentUser and currentUser.isInGroup('sales') %}
  {% redirect "new.url" %}
  {% endif %}
  </code></pre>
  
  <p>...somewhere on the page that logged in users will land on by default.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-27T15:16:49.553Z
Answers.Text: I need to tie into the onLogin event and redirect to a url different from the control panel on login if the user is part of a particular group. Any other ideas how this might be done?
Answers.UserDisplayName: Nicholas Mann
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-27T15:19:34.680Z
Answers.Text: Makes sense, I had assumed this was for the front-end. Where is the login form, is it the default CP login page, or your own front-end template. If the latter, then my best guess is `getCsrfInput()` not being set up correctly.
Answers.UserDisplayName: Mike Pierce
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-27T14:59:45.827Z
Answers.LastActivityDate: 2017-04-27T15:24:31.363Z
Answers.LastEditDate: 2017-04-27T15:24:31.363Z
Answers.UserDisplayName: Mike Pierce
Body: <p>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:</p>
  
  <pre><code>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);
          }
      });
  }
  </code></pre>
  
  <p>Please advise.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-27T14:55:59.997Z
Comments.Text: Have you got dev mode switched on, that might show a bit more information to track down what's going wrong.
Comments.UserDisplayName: Mike Pierce
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-27T15:09:47.193Z
Comments.Text: I do, unfortunately it's not giving me any useful info.
Comments.UserDisplayName: Nicholas Mann
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-27T15:17:15.763Z
Comments.Text: I'm stumped, the code seems sound. What about the form that you're submitting for the login, do you have `getCsrfInput()` set up correctly?
Comments.UserDisplayName: Mike Pierce
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-27T15:19:07.147Z
Comments.Text: I have a custom cpTrigger url, and that's the page I'm using. No alternate login page is being used.
Comments.UserDisplayName: Nicholas Mann
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-27T15:20:39.430Z
Comments.Text: Ok, then I'm out of ideas. :(
Comments.UserDisplayName: Mike Pierce
Tags: <craft-features>
Title: Redirect user based on group after Craft login
ThreadText: # Redirect user based on group after Craft login
  
  (Asked by: username_0 on 2017-04-27)
  
  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()->on( 'userSession.onLogin', function( Event $event ){
          $user = craft()->userSession->getUser();
          if ($user && $user->isInGroup('sales')){
            $url = "new.url";
            craft()->request->redirect($url);
          }
      });
  }
  
  ```
  
  Please advise.
  
  **Tags:** craft-features
  
  > **Comments:**
  > **username_1**: Have you got dev mode switched on, that might show a bit more information to track down what's going wrong.  
  > **username_0**: I do, unfortunately it's not giving me any useful info.  
  > **username_1**: I'm stumped, the code seems sound. What about the form that you're submitting for the login, do you have `getCsrfInput()` set up correctly?  
  > **username_0**: I have a custom cpTrigger url, and that's the page I'm using. No alternate login page is being used.  
  > **username_1**: Ok, then I'm out of ideas. :(  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-04-27. Score: 1
  
  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.
  
  > **Comments:**
  > **username_0**: I need to tie into the onLogin event and redirect to a url different from the control panel on login if the user is part of a particular group. Any other ideas how this might be done?  
  > **username_1**: Makes sense, I had assumed this was for the front-end. Where is the login form, is it the default CP login page, or your own front-end template. If the latter, then my best guess is `getCsrfInput()` not being set up correctly.  
  
  ---
  
  