11import { auth , currentUser } from "@clerk/nextjs/server" ;
2- import { Liveblocks } from "@liveblocks/node" ;
3- import { ConvexHttpClient } from "convex/browser" ;
4- import { api } from "../../../../../convex/_generated/api" ;
2+ // import { Liveblocks } from "@liveblocks/node";
3+ // import { ConvexHttpClient } from "convex/browser";
4+ // import { api } from "../../../../../convex/_generated/api";
55
6- const convex = new ConvexHttpClient ( process . env . NEXT_PUBLIC_CONVEX_URL ! ) ;
7- const liveblocks = new Liveblocks ( {
8- secret : process . env . LIVE_BLOCK_SECRET_API_KEY ! ,
9- } ) ;
6+ // const convex = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL!);
7+ // const liveblocks = new Liveblocks({
8+ // secret: process.env.LIVE_BLOCK_SECRET_API_KEY!,
9+ // });
1010
1111export async function POST ( req : Request ) {
1212 const { sessionClaims } = await auth ( ) ;
@@ -16,30 +16,31 @@ export async function POST(req: Request) {
1616 if ( ! user ) return new Response ( "Unauthorized" , { status : 401 } ) ;
1717
1818 const { room } = await req . json ( ) ;
19- const document = await convex . query ( api . document . get , {
20- id : room ,
21- ignoreAuth : true ,
22- } ) ;
23-
24- if ( ! document ) return new Response ( "Unauthorized" , { status : 401 } ) ;
25-
26- const isOwner = document . ownerId === user . id ;
27- const isOrgMember = ! ! (
28- document . organizationId && document . organizationId === sessionClaims . org_id
29- ) ;
30-
31- if ( ! isOwner && ! isOrgMember )
32- return new Response ( "Unauthorized" , { status : 401 } ) ;
33-
34- const session = liveblocks . prepareSession ( user . id , {
35- userInfo : {
36- name :
37- user . fullName ?? user . primaryEmailAddress ?. emailAddress ?? "Anonymous" ,
38- avatar : user . imageUrl ,
39- } ,
40- } ) ;
41-
42- session . allow ( room , session . FULL_ACCESS ) ;
43- const { body, status } = await session . authorize ( ) ;
44- return new Response ( body , { status } ) ;
19+ // const document = await convex.query(api.document.get, {
20+ // id: room,
21+ // ignoreAuth: true,
22+ // });
23+
24+ // if (!document) return new Response("Unauthorized", { status: 401 });
25+
26+ // const isOwner = document.ownerId === user.id;
27+ // const isOrgMember = !!(
28+ // document.organizationId && document.organizationId === sessionClaims.org_id
29+ // );
30+
31+ // if (!isOwner && !isOrgMember)
32+ // return new Response("Unauthorized", { status: 401 });
33+
34+ // const session = liveblocks.prepareSession(user.id, {
35+ // userInfo: {
36+ // name:
37+ // user.fullName ?? user.primaryEmailAddress?.emailAddress ?? "Anonymous",
38+ // avatar: user.imageUrl,
39+ // },
40+ // });
41+
42+ // session.allow(room, session.FULL_ACCESS);
43+ // const { body, status } = await session.authorize();
44+ // return new Response(body, { status });
45+ return new Response ( room , { status : 200 } ) ;
4546}
0 commit comments