I’m trying to insert data into a Supabase table using a Next.js server action, but I’m encountering the following error:
Error: Failed to create log pool: permission denied for schema public
Here is my setup:
Server Action:
'use server';
import { createClient } from "@/utils/supabase/server";
import { revalidatePath } from 'next/cache';
export async function createLogPool(data: FormData) {
const name = data.get('name') as string | null;
const description = data.get('description') as string | null;
const orgId = data.get('organization') as string | null;
const supabase = createClient();
if (!name || !description || !orgId) {
throw new Error('All fields are required');
}
const { error } = await supabase.from('LogPool').insert({
name,
description,
orgId: orgId
});
if (error) {
console.error('Supabase Error:', error);
throw new Error(`Failed to create log pool: ${error.message}`);
}
revalidatePath('/settings');
}
Modal Form (Client-Side):
"use client";
import { DialogContent, DialogHeader, DialogTitle, DialogDescription } from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
import { Label } from "@/components/ui/label";
import { createLogPool } from "../actions";
export default function NewPoolModal() {
return (
<DialogContent>
<DialogHeader>
<DialogTitle>New Pool</DialogTitle>
<DialogDescription>Create a new log pool</DialogDescription>
</DialogHeader>
<form action={createLogPool} className="space-y-4">
<div>
<Label htmlFor="name">Name</Label>
<Input id="name" name="name" placeholder="Enter pool name" required />
</div>
<div>
<Label htmlFor="description">Description</Label>
<Input id="description" name="description" placeholder="Enter pool description" required />
</div>
<div>
<Label htmlFor="organization">Organization</Label>
<Input id="organization" name="organization" value="688202df-6e7d-41a4-bd3c-a304038e4816" readOnly />
</div>
<Button type="submit" className="w-full mt-4 bg-blue-600 hover:bg-blue-700">Create Pool</Button>
</form>
</DialogContent>
);
}
To resolve the permission issue, I tried enabling Row-Level Security (RLS) and added a policy:
create policy "Allow insert access" on public."LogPool" for insert with check ( true );
--also
npx prisma migrate deploy
However, I’m still getting the “permission denied for schema public” error.
I believe there might be something wrong with either the RLS configuration or the policy setup. Any advice on how to correctly set permissions for inserts would be greatly appreciated!
PS : I’ve forgot to join Policies about table but i just joined it