feat: [US-044] - Project sharing and collaborator management

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Gustavo Henrique Santos Souza de Miranda
2026-01-23 15:36:58 -03:00
co-authored by Claude Opus 4.5
parent 46b681462d
commit 37031c3889
7 changed files with 594 additions and 46 deletions
+32 -3
View File
@@ -20,15 +20,43 @@ export default async function EditorPage({ params }: PageProps) {
return null
}
const { data: project, error } = await supabase
// Try to load as owner first
const { data: ownedProject } = await supabase
.from('projects')
.select('id, name, flowchart_data')
.eq('id', projectId)
.eq('user_id', user.id)
.single()
if (error || !project) {
notFound()
let project = ownedProject
let isOwner = true
// If not the owner, check if the user is a collaborator
if (!project) {
// RLS on projects allows collaborators to SELECT shared projects
const { data: collab } = await supabase
.from('project_collaborators')
.select('id, role')
.eq('project_id', projectId)
.eq('user_id', user.id)
.single()
if (!collab) {
notFound()
}
const { data: sharedProject } = await supabase
.from('projects')
.select('id, name, flowchart_data')
.eq('id', projectId)
.single()
if (!sharedProject) {
notFound()
}
project = sharedProject
isOwner = false
}
const rawData = project.flowchart_data || {}
@@ -74,6 +102,7 @@ export default async function EditorPage({ params }: PageProps) {
<FlowchartEditor
projectId={project.id}
userId={user.id}
isOwner={isOwner}
initialData={flowchartData}
needsMigration={needsMigration}
/>