
how to post
2 min read β’ 8 views
Unknown Author
March 25, 2026
Good β this helps pinpoint the issue exactly π
Your current policy:
`sql
alter policy "Users can insert their own posts"
on "public"."posts"
to public
with check (
(auth.uid() = author_id)
);
`
---
π¨ Whatβs wrong (2 key problems)
β 1. `TO public`
- `public` = **anyone (even not logged in)**
- But `auth.uid()` only works for **authenticated users**
π This creates a mismatch β policy fails
---
β 2. Column mismatch (`author_id` vs your code)
Earlier we used:
`sql
user_id
`
Now your policy uses:
`sql
author_id
`
π If your insert is sending user_id but policy checks author_id
β β RLS blocks it
---
β Fix (Clean & Correct)
Option A (Recommended β use `author_id`)
If your table uses author_id, then fix policy like this:
`sql
ALTER POLICY "Users can insert their own posts"
ON public.posts
TO authenticated
WITH CHECK (auth.uid() = author_id);
`
---
Option B (If your column is `user_id`)
`sql
ALTER POLICY "Users can insert their own posts"
ON public.posts
TO authenticated
WITH CHECK (auth.uid() = user_id);
`
---
π₯ MOST IMPORTANT: Match your code
Your insert MUST match the column:
If using `author_id`:
`js
await supabase.from('posts').insert([
{
title,
content,
author_id: user.id // β
MUST match policy
}
])
`
---
π§ͺ Quick Debug Checklist
- [ ] Is user logged in?
- [ ] Column name matches? (`author_id` vs `user_id`)
- [ ] Policy uses `TO authenticated` (NOT public)
- [ ] Insert includes that column
---
β‘ Fast Test (to confirm issue)
Temporarily run:
`sql
ALTER POLICY "Users can insert their own posts"
ON public.posts
TO authenticated
WITH CHECK (true);
`
π If it works β issue is 100% column mismatch
---
π§ Final Answer
β Your policy exists β good β But:
- Wrong role (`public`)
- Possible column mismatch
π Fix those β error gone instantly
---
If you want, paste your:
- `posts` table structure
- `createPost` code
Iβll align everything perfectly so it just works π