__loggedInUserId in Custom Function

What’s the alternative for __loggedInUserId in a Custom Function resolver?

Hey @chanand - when you ask for an “alternative”, what are you trying to accomplish?

One thing that may help is the ability to specify is_self for any relation to a User record. For example,

await ctx.api.gqlRequest(`
query {
  usersList(filter: {
    friends: {
	some: {
	  is_self: true
      }
    }
  }) {
    count
  }
}
`) 

In this example, a list of users who the REQUESTING user is friends with would be returned.

Is this helpful?

Is there a way to get the actual user ID from the ctx?
Or is the only way getting it would be by executing a gqlRequest?

There isn’t a current user id key that you have access to on cxt. If you need the actual uuid of the user, you can either send it to the custom function as an argument (from the client-app) OR make an api call to retrieve the current user ID.

export default async (event: any, ctx: any) : Promise<LocalizeResult> => {
   // I need the user ID, asap!
   const { user: { id }  } = await ctx.api.gqlRequest('query { user { id } }');
   // I've got my id!
   sendEmail({ msg: `You're ID is: ${id}` });
   
   return {
     status: 200,
     response: "I'm so happy!"
   }
};

Also, could you let me know what you’re trying to accomplish? Maybe we should add the id :slight_smile: