Okay, for others who have the same problem. I found another solution. Now I’m using in src/index.js
the bootstrap({ strapi }) {}
function.
In my case the code looks like this:
strapi.db.lifecycles.subscribe({
models: ['plugin::users-permissions.user'],
async afterCreate(event) {
// Save new internal user id to database
let sql = `SELECT internal_user_id
FROM up_users
ORDER BY internal_user_id DESC LIMIT 1`
let last_internal_user_id = await strapi.db.connection.raw(sql)
last_internal_user_id = last_internal_user_id[0][0].internal_user_id
last_internal_user_id++
sql = `UPDATE up_users
SET internal_user_id = ${last_internal_user_id}
WHERE id = ${event.result.id}`
await strapi.db.connection.raw(sql)
// Add user and club to Club_User database
if (event.params.data.club_id.connect.length > 0) {
await Promise.all(event.params.data.club_id.connect.map(async (club) => {
sql = `INSERT INTO club_users
(user_id, club_id, is_admin, membership_starts, membership_ends)
VALUES (${event.result.id}, ${club.id}, false, NOW(), NOW())`
await strapi.db.connection.raw(sql)
}))
}
return true
},
async beforeCreate(event) {
console.log('beforeCreate', event)
},
});
},```