How to get logged in User details in Nestjs agent?

I am using ForestAdmin agent mounted on Nestjs, and I need to access the logged in User details (email or name) when they hit certain actions that I am customizing. Is that possible?


Here is my agent setup and customizations:

 const agent = createAgent<Schema>({
      authSecret: xxx,
      envSecret: xxx,
      isProduction: process.env.NODE_ENV === 'production',
      typingsPath: `${__dirname}/typings.ts`,
      schemaPath: `${__dirname}/../.forestadmin-schema.json`,
      typingsMaxDepth: 5,
        createSqlDataSource('connection string'),
      .customizeCollection('invoices', InvoicesCustomization(app))
      .customizeCollection('credit_notes', CreditNotesCustomization(app))
      .customizeCollection('accounts', AccountsCustomization(app))

    await agent.mountOnNestJs(app).start()
    await app.listen(3050)

hello @Nader_Kanounji and welcome to our community.

Indeed, it is possible to access some user details from the action context object that is passed to your execute callback, like so:

  collection.addAction('Change data', {
    scope: 'Single',
    execute: async (actionContext, resultBuilder) => {
      const { email, firstName } = actionContext.caller;
      // your logic here

The documentation for actions context in your stack is here. It seems like it is missing info about the caller data though, so I will update it shortly to fix that.

I see that you are using typescript: please note that all our interfaces expose proper typing to help you use them.


I have added information about the caller in the documentation.

1 Like

Thanks! I missed that part…