Conditionally check if a get request is authenticated or public

I would like to check if the incoming get request has come through public endpoint or through authenticated. Is there a way to check this?

If it is an authenticated request, I would like to show the user more information.
if the request has come via public, then I would like to show the user less information.

The logic I am seeking should do the following (pseudo code)

async findOne(ctx){
    const { id } = ctx.params;
    let entity = await{ id });
   // ** conditional logic here **
   // if request is authenticated
   // show meta data
   // Else
   // show limited information

return entity;
System Information
  • Strapi Version: 3.6.5
  • Operating System: macOS 12
  • Database: Postgress
  • Node Version: v14.15
  • NPM Version: 6.14

You should be able to tell if the request has a user associated with it (i.e is an authenticated request) by checking for the existence of ctx.state.user. E.g

const isAuthenticated = !!ctx.state.user;
if (isAuthenticated) {
} else {