0

I'm making a basic chat app using supabase. I've figured out how to make it so users can only create/edit their profile and send messages from their profile using RLS, by checking if their id matches with the auth.id.

The problem I'm facing is, that I don't want users to be able to insert messages with wrong creation dates. If no date is specified the default value is correct. But currently there is no check for the creation date. Can I specify, that the creation date field has to be sent empty? Is there maybe a better solution?

1 Answer 1

1

One thing you can do is you can override the created_at field with the current server timestamp using triggers.

Code not verified, so you might have to make some small adjustments, but the idea is this:

create extension if not exists moddatetime schema extensions;

-- assuming the table name is "messages", and a timestamp column "created_at"
-- this trigger will set the "created_at" column to the current timestamp for every insert
create trigger
  handle_created_at before insert
on messages
for each row execute
  procedure moddatetime(created_at);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.