Answers.Body: <p>I believe the way to do this would be to have your plugin listen for the <a href="http://buildwithcraft.com/docs/plugins/events-reference#userSession-onBeforeLogin" rel="nofollow">onBeforeLogin</a> event.</p>
  
  <p>From inside there, you'd check to see if the there is an existing session <code>craft()-&gt;userSession-&gt;isLoggedIn()</code> and the current user is an admin <code>craft()-&gt;userSession-&gt;isAdmin()</code>.</p>
  
  <p>If both of those are true, I believe its going to be a pretty safe assumption that an admin just clicked the "Login as User" button.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-17T07:30:51.083Z
Answers.Text: To be clear, this is only detectable **at the moment of fake login?** Once the user has switched accounts, there's no way to distinguish between a real login and a fake login.
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-17T16:02:00.637Z
Answers.Text: Yeah, I can't think of any way to distinguish the two, currently. Ultimately they both end up using the same login logic.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-17T16:27:18.240Z
Answers.Text: That's what I figured. Thanks for the clarification!
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-16T22:49:12.757Z
Answers.LastActivityDate: 2014-12-16T22:49:12.757Z
Answers.UserDisplayName: Brad Bell
Body: <p>From a plugin, how would I go about detecting if an admin user is using the "Login as User" feature?</p>
  
Tags: <plugin-development>
Title: Detecting "Login as User" session
ThreadText: # Detecting "Login as User" session
  
  (Asked by: username_0 on 2014-12-16)
  
  From a plugin, how would I go about detecting if an admin user is using the "Login as User" feature?
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-12-16. Score: 4 | Accepted answer
  
  I believe the way to do this would be to have your plugin listen for the [onBeforeLogin](http://buildwithcraft.com/docs/plugins/events-reference#userSession-onBeforeLogin) event.
  
  From inside there, you'd check to see if the there is an existing session `craft()->userSession->isLoggedIn()` and the current user is an admin `craft()->userSession->isAdmin()`.
  
  If both of those are true, I believe its going to be a pretty safe assumption that an admin just clicked the "Login as User" button.
  
  > **Comments:**
  > **username_2**: To be clear, this is only detectable **at the moment of fake login?** Once the user has switched accounts, there's no way to distinguish between a real login and a fake login.  
  > **username_1**: Yeah, I can't think of any way to distinguish the two, currently. Ultimately they both end up using the same login logic.  
  > **username_2**: That's what I figured. Thanks for the clarification!  
  
  ---
  
  