realtime empty payload.new - error 401: Unauthorized

I have supabase "realtime" setup for one of my tables "ReportIdeally" and I am receiving a payload when a change happens but payload.new (and payload.old) is always empty. See below example
{
"payload": {
"schema": "public",
"table": "ReportIdeally",
"commit_timestamp": null,
"eventType": "UPDATE",
"new": {},
"old": {},
"errors": [
"Error 401: Unauthorized"
]
}
}
{
"payload": {
"schema": "public",
"table": "ReportIdeally",
"commit_timestamp": null,
"eventType": "UPDATE",
"new": {},
"old": {},
"errors": [
"Error 401: Unauthorized"
]
}
}
I am listening to Realtime via the following:
useEffect(() => {

const runsupabase =
supabase
.channel("any")
.on(
"postgres_changes",
{
event: "*",
schema: "public",
table: "*",
},
(payload) => {
console.log("New Payload", {payload});
}
)
.subscribe();
return () => {
supabase.removeChannel(runsupabase)
}

}, [supabase]);
useEffect(() => {

const runsupabase =
supabase
.channel("any")
.on(
"postgres_changes",
{
event: "*",
schema: "public",
table: "*",
},
(payload) => {
console.log("New Payload", {payload});
}
)
.subscribe();
return () => {
supabase.removeChannel(runsupabase)
}

}, [supabase]);
And of course I have the relevant table enabled. I don't have RLS enabled yet so I am stumped to why this still doesn't return a payload with the updated item? Is it to do with an authentication issue? Do I need to add an Auth bearer in the header even though I have no authentication setup yet? My Supabase init is as follows:
import { createClient } from "@supabase/supabase-js";

export const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_KEY!
);
import { createClient } from "@supabase/supabase-js";

export const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_KEY!
);
The resulting payload object is as follows:
{
"payload": {
"schema": "public",
"table": "LotInterest",
"commit_timestamp": null,
"eventType": "UPDATE",
"new": {},
"old": {},
"errors": [
"Error 401: Unauthorized"
]
}
}
{
"payload": {
"schema": "public",
"table": "LotInterest",
"commit_timestamp": null,
"eventType": "UPDATE",
"new": {},
"old": {},
"errors": [
"Error 401: Unauthorized"
]
}
}
9 Replies
garyaustin
garyaustin2y ago
You have to meet select RLS for the table if RLS is enabled.
Simon  📐🛠
Simon 📐🛠OP2y ago
No as I said I have RLS disabled in the attempt to just get it to work before applying any filtering / securing of rows. I tried it out on the RealTime Inspector on the SupaBase website with system_role with admin privilege's and it still responds the same
{
"schema": "public",
"table": "Lot",
"commit_timestamp": null,
"eventType": "UPDATE",
"new": {},
"old": {},
"errors": [
"Error 401: Unauthorized"
],
"latency": null
}
{
"schema": "public",
"table": "Lot",
"commit_timestamp": null,
"eventType": "UPDATE",
"new": {},
"old": {},
"errors": [
"Error 401: Unauthorized"
],
"latency": null
}
garyaustin
garyaustin2y ago
Do you use Prisma?
Simon  📐🛠
Simon 📐🛠OP2y ago
UhOh Yes?
garyaustin
garyaustin2y ago
It likely wiped out your grants. Hang on.
Simon  📐🛠
Simon 📐🛠OP2y ago
Thanks a lot for the quick reply
garyaustin
garyaustin2y ago
Can you go to that tab and scroll down to Prisma and click it. I'm getting 404 right now on the Prisma page. Which shows how to fix the grants on the schema when Prisma resets them.
No description
Simon  📐🛠
Simon 📐🛠OP2y ago
ok awesome I will take a look
garyaustin
garyaustin2y ago
If the page is not working for you this shows the SQL to run on the schema and tables to restore them. It does not have the surrounding info, but should get you going. https://github.com/supabase/supabase/issues/13579
GitHub
Missing default grants defined in your database after running Prism...
Describe the bug If you run prisma migrate dev and it detects schema drift, it asks you if you want to reset the database. If you choose yes, it will reset the database and from there, it is no lon...

Did you find this page helpful?