Skip to content

Commit b757b10

Browse files
authored
Merge pull request #15 from duylongpro99/development
feat: room document with multiple users, update document realtime
2 parents 1f6f0ca + 1b0b2bb commit b757b10

File tree

15 files changed

+742
-17
lines changed

15 files changed

+742
-17
lines changed

.github/workflows/deploy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ jobs:
123123
echo "CLERK_SECRET_KEY=${{ secrets.CLERK_SECRET_KEY }}" >> .env
124124
echo "NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=${{ secrets.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY }}" >> .env
125125
126+
# Liveblocks secret key:
127+
echo "LIVE_BLOCK_SECRET_API_KEY=${{secrets.LIVE_BLOCK_SECRET_API_KEY}}" >> .env
128+
126129
# Install Vercel CLI
127130
- name: Install Vercel CLI
128131
run: npm install --global vercel@latest

convex/document.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ export const remove = mutation({
8080
| string
8181
| undefined;
8282

83-
if (doc.ownerId !== user.subject && doc.organizationId !== organizationId)
83+
if (
84+
doc.ownerId !== user.subject &&
85+
!!(doc.organizationId && doc.organizationId !== organizationId)
86+
)
8487
throw new ConvexError("Unauthorized");
8588

8689
return await ctx.db.delete(args.documentId);
@@ -100,9 +103,29 @@ export const update = mutation({
100103
| string
101104
| undefined;
102105

103-
if (doc.ownerId !== user.subject && doc.organizationId !== organizationId)
106+
if (
107+
doc.ownerId !== user.subject &&
108+
!!(doc.organizationId && doc.organizationId !== organizationId)
109+
)
104110
throw new ConvexError("Unauthorized");
105111

106112
return await ctx.db.patch(args.documentId, { title: args.title });
107113
},
108114
});
115+
116+
export const get = query({
117+
args: { id: v.id("documents"), ignoreAuth: v.optional(v.boolean()) },
118+
handler: async (ctx, { id, ignoreAuth }) => {
119+
if (!ignoreAuth) {
120+
const user = await ctx.auth.getUserIdentity();
121+
if (!user) throw new ConvexError("Unauthorized");
122+
}
123+
124+
const doc = await ctx.db.get(id);
125+
if (!doc) {
126+
throw new ConvexError("Document not found");
127+
}
128+
129+
return doc;
130+
},
131+
});

liveblocks.config.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Define Liveblocks types for your application
2+
// https://liveblocks.io/docs/api-reference/liveblocks-react#Typing-your-data
3+
declare global {
4+
interface Liveblocks {
5+
// Each user's Presence, for useMyPresence, useOthers, etc.
6+
Presence: {
7+
// Example, real-time cursor coordinates
8+
// cursor: { x: number; y: number };
9+
};
10+
11+
// The Storage tree for the room, for useMutation, useStorage, etc.
12+
Storage: {
13+
// Example, a conflict-free list
14+
// animals: LiveList<string>;
15+
};
16+
17+
// Custom user info set when authenticating with a secret key
18+
UserMeta: {
19+
id: string;
20+
info: {
21+
// Example properties, for useSelf, useUser, useOthers, etc.
22+
// name: string;
23+
// avatar: string;
24+
};
25+
};
26+
27+
// Custom events, for useBroadcastEvent, useEventListener
28+
RoomEvent: {};
29+
// Example has two events, using a union
30+
// | { type: "PLAY" }
31+
// | { type: "REACTION"; emoji: "🔥" };
32+
33+
// Custom metadata set on threads, for useThreads, useCreateThread, etc.
34+
ThreadMetadata: {
35+
// Example, attaching coordinates to a thread
36+
// x: number;
37+
// y: number;
38+
};
39+
40+
// Custom room info set with resolveRoomsInfo, for useRoomInfo
41+
RoomInfo: {
42+
// Example, rooms with a title and url
43+
// title: string;
44+
// url: string;
45+
};
46+
}
47+
}
48+
49+
export {};

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
"@clerk/clerk-react": "^5.24.1",
1313
"@clerk/nextjs": "^6.12.4",
1414
"@hookform/resolvers": "^3.10.0",
15+
"@liveblocks/client": "^2.20.0",
16+
"@liveblocks/node": "^2.20.0",
17+
"@liveblocks/react": "^2.20.0",
18+
"@liveblocks/react-tiptap": "^2.20.0",
19+
"@liveblocks/react-ui": "^2.20.0",
1520
"@radix-ui/react-accordion": "^1.2.2",
1621
"@radix-ui/react-alert-dialog": "^1.1.5",
1722
"@radix-ui/react-aspect-ratio": "^1.1.1",

0 commit comments

Comments
 (0)