Detect current user and admin in service

I need to detect inside a service function:

  • whether the current user is authenticated and is it an admin panel user or site user
  • wether the code was executed from admin of from CLI

How do I do that?

I’m not sure why you want to check if the user is authenticated, you cannot get into the panel if you are not authenticated. In either case, you can get from the admin context which type of user it is.

Also, from the admin context you could check if the action is ran from admin or from CLI, but I’m not sure about that.

I need this because I want to have different logic in afterFIndOne() for the public site and admin interface.

How do I get this?

I don’t remember how to do this exactly, but you have the request lifecycle, from those functions you can get the context, either debugging it or printing it in the console you can find the exact property you are looking for.