Visualforce Page:
<apex:page controller=”CommunityPageController”>
Logged in As User? {!loggedInAsUserBool}
</apex:page>
Apex Controller:
public class CommunityPageController {
public Boolean loggedInAsUserBool { get; set; }
public CommunityPageController() {
loggedInAsUserBool = false;
Map < String, String > currentSessionInfo = Auth.SessionManagement.getCurrentSession();
if ( currentSessionInfo.get( ‘LoginHistoryId’ ) == null &&
currentSessionInfo.get( ‘LoginType’ ) == ‘Unknown’ &&
currentSessionInfo.get( ‘LogoutUrl’ ) == null ) {
loggedInAsUserBool = true;
}
}
}
Logged in As Experience User(without impersonation):
Admin Logged in As Experience User(with impersonation):
For LWC(Lighting Web Component), check https://www.infallibletechie.com/2021/05/lightning-web-component-to-find-whether.html.