how to post
Tech

how to post

2 min read β€’ 8 views

A

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 πŸ‘

Share this article

Quiz: Test Your Knowledge

Check how much you learned from this article

Comments (0)

Please log in to leave a comment.

No comments yet. Be the first to share your thoughts!

Popular Articles

Bookmarks

Sign in to see your bookmarks

Sponsored

Upgrade to Pro

Get unlimited access to premium articles and exclusive content.