How to store the record owner?

System Information
  • Strapi Version: 4.13.1
  • Operating System:
  • Database:
  • Node Version:
  • NPM Version:
  • Yarn Version:

I have “Roles & Permissions” plugin installed.
I want to record down who create a record.
i.e. Someone signed-in, called POST REST-API with JWT, his identity is stored with the record.

On this page, it says the user-id is ctx.state.user:

However, I have got empty ctx.state in my code:
services/mymodule.ts

import { factories } from '@strapi/strapi';

module.exports = factories.createCoreService('api::mymodule.mymodule', {
  async create(ctx) {
    const { user_id } = ctx.state.user;
    const form_data = ctx.request.body;

    let res = await strapi.entityService.create("api::mymodule.mymodule", {
      data: {
        User: user_id,
        ...form_data,
      },
    });
  }
});

What is the correct way to achieve this?

Thanks.