Fixed conversation creation RLS
X-Lovable-Edit-ID: edt-6ec5edf2-d491-40a6-a968-ce92ffa730cb Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
@@ -298,14 +298,13 @@ function NewConversationDialog({ profiles, onCreated }: { profiles: Profile[]; o
|
||||
}
|
||||
setBusy(true);
|
||||
try {
|
||||
const { data: conv, error } = await supabase
|
||||
const convId = crypto.randomUUID();
|
||||
const { error } = await supabase
|
||||
.from("conversations")
|
||||
.insert({ type, name: type === "channel" ? name.trim() : null, created_by: user.id })
|
||||
.select("id")
|
||||
.single();
|
||||
if (error || !conv) throw error;
|
||||
.insert({ id: convId, type, name: type === "channel" ? name.trim() : null, created_by: user.id });
|
||||
if (error) throw error;
|
||||
const memberRows = [user.id, ...Array.from(selected)].map((uid) => ({
|
||||
conversation_id: conv.id,
|
||||
conversation_id: convId,
|
||||
user_id: uid,
|
||||
}));
|
||||
const { error: mErr } = await supabase.from("conversation_members").insert(memberRows);
|
||||
@@ -313,7 +312,7 @@ function NewConversationDialog({ profiles, onCreated }: { profiles: Profile[]; o
|
||||
toast.success("Conversation created");
|
||||
setOpen(false);
|
||||
reset();
|
||||
onCreated(conv.id);
|
||||
onCreated(convId);
|
||||
} catch (e: any) {
|
||||
toast.error(e.message || "Failed to create conversation");
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user