Efficiently Adding a Custom Relational Field to ctx.state.user in Strapi V4 for Every Request

System Information
  • Strapi Version: 4.17.1
  • Operating System: Windows 11
  • Database: SQLite
  • Node Version: 18
  • NPM Version: 9.8.1

Hello,

I’m working on a project where I need to incorporate and populate a custom relational field (which I’ll refer to as store - each user has one store) from the users-permissions table into ctx.state.user for every request.

While researching, I came across a discussion in the forum: Adding relational data to the user model/collection in the ctx.state.user - Questions and Answers / Database-MongoDB - Strapi Community Forum. However, this thread is somewhat outdated and is related to Strapi V3. I’m hesitant about repeatedly fetching the user with the query engine as suggested in the mentioned example, especially since this process seems to be already executed once to populate the existing information in ctx.state.user.

Is there a more efficient method to consistently access my relational store field in ctx.state.user across all requests, without negatively impacting performance?

Thank you!