Sharing & Workspace Invites
Relevant source files
The following files were used as context for generating this wiki page:
Sharing and Workspace Invites in ThinkEx facilitate collaborative work by allowing users to invite others to their workspaces with specific permission levels or share content as independent copies. The system supports direct email invitations, shareable collaboration links, and "Share as Copy" functionality for deep-cloning workspaces.
Collaborative features are restricted to authenticated users; anonymous sessions are prompted to sign in or sign up to manage access. Sources: src/components/workspace/ShareWorkspaceDialog.tsx:57-60, src/components/workspace/ShareWorkspaceDialog.tsx:313-330
Architecture and Data Flow
The sharing system is built on a set of API endpoints that manage three primary entities: Collaborators, Invites, and Share Links.
Collaboration Model
ThinkEx uses a role-based access control (RBAC) model with three distinct permission levels:
- Owner: Has full control over the workspace, including deleting it and managing all collaborators. Sources: src/components/workspace/ShareWorkspaceDialog.tsx:66-68
- Editor: Can view and edit workspace content and invite new collaborators. Sources: src/components/workspace/ShareWorkspaceDialog.tsx:71-72, src/app/api/workspaces/[id]/collaborators/route.ts:133-134
- Viewer: Can only view the workspace and list its current collaborators. Sources: src/components/workspace/ShareWorkspaceDialog.tsx:71-72, src/app/api/workspaces/[id]/collaborators/route.ts:51-52
Invitation Flow
When an invitation is sent, the system distinguishes between existing users and new users. Existing users are added directly as collaborators, while new users receive a "Pending Invite" with a unique token.
Sharing Mechanisms
Collaborative Share Links
Collaborative links allow users to join a workspace via a unique URL. These links are ephemeral, typically expiring after 7 days. Sources: src/components/workspace/ShareWorkspaceDialog.tsx:645-647, src/app/api/workspaces/[id]/collaborators/route.ts:208-209
Share as Copy (Deep Copy)
Unlike collaborative sharing, "Share as Copy" provides a URL that allows recipients to import an independent snapshot of the workspace. This does not grant access to the original workspace and the links do not expire. Sources: src/components/workspace/ShareWorkspaceDialog.tsx:645-647, src/app/share-copy/[id]/layout.tsx:39-44
Bulk Sharing
Users can select multiple workspace IDs and invite collaborators to all of them simultaneously. In bulk mode, individual collaborator management is hidden, and the focus is shifted to sending mass invitations. Sources: src/components/workspace/ShareWorkspaceDialog.tsx:61-63, src/components/workspace/ShareWorkspaceDialog.tsx:162-192
Data Structures and API Endpoints
API Summary
| Endpoint | Method | Description |
|---|---|---|
/api/workspaces/[id]/collaborators | GET | Lists all active collaborators and pending invites for a workspace. |
/api/workspaces/[id]/collaborators | POST | Invites a user via email. Adds directly if user exists, otherwise creates pending invite. |
/api/workspaces/[id]/collaborators/[collabId] | PATCH | Updates the permission level of an existing collaborator. |
/api/workspaces/[id]/collaborators/[collabId] | DELETE | Removes a collaborator from the workspace. |
/api/workspaces/[id]/invites/[inviteId] | DELETE | Revokes a pending invitation token. |
Sources: src/app/api/workspaces/[id]/collaborators/route.ts:8-12, src/components/workspace/ShareWorkspaceDialog.tsx:219-234, src/components/workspace/ShareWorkspaceDialog.tsx:244-275
Core Schema Relationships
Implementation Details
Token Generation
Pending invites use a 24-byte secure random hex token generated via the Web Crypto API (falling back to a random string if crypto is unavailable).
Sources: src/app/api/workspaces/[id]/collaborators/route.ts:189-204
Email Integration
The system integrates with Resend to deliver invitations. It uses an idempotency key formatted as invite-[type]-[workspaceId]-[email] to prevent duplicate emails during retries.
Sources: src/app/api/workspaces/[id]/collaborators/route.ts:153-170, src/app/api/workspaces/[id]/collaborators/route.ts:223-238
SEO and Metadata for Shared Links
Dynamic metadata is generated for invite and copy links to provide rich previews in social platforms and messaging apps. This includes the workspace name, icon, and specific descriptions depending on whether the link is an invite or a copy link.
Sources: src/app/invite/link/[token]/layout.tsx:13-75, src/app/share-copy/[id]/layout.tsx:15-62
Conclusion
Sharing and Workspace Invites form the backbone of collaboration in ThinkEx. By supporting both real-time multi-user collaboration via roles and static sharing via copies, the system accommodates different knowledge-sharing workflows while maintaining security through email verification and expiring tokens.