How to retrieve frontend user from lifecycle beforeUpdate?

Hi guys, the idea is following:
I want to catch any modification on entity and write it in another log entity using lifecycles.js.
The problem I don’t know how to retrieve the user ID who made this request, if it modified from UI so OK, I have his ID but if he makes a modification from my next.js application so I don’t have this ID.
any ideas?

My code:

	beforeUpdate: async ({params}) => {

		//--- insert log ---
		try{
			const diff = await getUpdateDifferences(params);
			const action = "Modified";
			const message = "Affected fields: " + JSON.stringify(diff);
			const entry = await strapi.db.query('api::log.log').create({
				action: action,
				message: message,
				user: ???????
			})

		}catch(error){
			console.log('ERROR:', error)
		}
	},

For that, you need to pass the logged in UserID into API body params from your next.js application.
After that you will get the UserID in the lifecycle params if the data was updated from the Frontend.

1 Like

Or get them from the JWT token in a middleware? ( @Shekhar )

Haven’t been through that yet.

What do you mean @Shekhar ?

Means, I haven’t gone through the solution for fetching user details from JWT token by using middleware.