Assign user automatically to created entity

Hi I am struggling with following scenario:

I have table messages
  • simple one message: text and author_id: ref-to-user
would like to build properly the logic on server level for following case:
1) User should not be able to set author_id manually to any message. I think this can be done with RLS, right?

2) Each time a new message is created I would like to assign author_id value equal to auth.uuid().

What's the right technique to get it done?
Was this page helpful?