PostgREST - Add authenticated user id on insert
Asked Answered
M

2

7

I need to automatically add an author of an inserted row in one of its columns. I am using postgREST (using Supabase cloud service) and I don't want users to add whoever they want as the author. Is there a way to automatically add user id of the user posting the data? Thanks!

Mortarboard answered 16/11, 2021 at 19:29 Comment(0)
M
5

The column's DEFAULT value should be:

  1. uid() for Supabase.
  2. current_user for Postgres.
Mortarboard answered 16/11, 2021 at 20:11 Comment(0)
D
8

You can add it via Table Editor or use auth.uid() in your SQL functions.

Admin Panel

Dog answered 30/12, 2021 at 12:25 Comment(0)
M
5

The column's DEFAULT value should be:

  1. uid() for Supabase.
  2. current_user for Postgres.
Mortarboard answered 16/11, 2021 at 20:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.