<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>

CC BY-SA 3.0
2014-12-17T07:30:51.083Z
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.
Lindsey D
CC BY-SA 3.0
2014-12-17T16:02:00.637Z
Yeah, I can't think of any way to distinguish the two, currently. Ultimately they both end up using the same login logic.
Brad Bell
CC BY-SA 3.0
2014-12-17T16:27:18.240Z
That's what I figured. Thanks for the clarification!
Lindsey D
CC BY-SA 3.0
2014-12-16T22:49:12.757Z
2014-12-16T22:49:12.757Z
Brad Bell
<p>From a plugin, how would I go about detecting if an admin user is using the "Login as User" feature?</p>

<plugin-development>
Detecting "Login as User" session
# 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!  

---

