mirror of
https://github.com/ahmadk953/tasko.git
synced 2025-05-01 19:29:33 +00:00
Added Very Basic Liveblocks Implimentation and README Updates
This commit is contained in:
parent
5a76ac0611
commit
0190fad583
12 changed files with 336 additions and 15 deletions
39
app/api/liveblocks-auth/route.ts
Normal file
39
app/api/liveblocks-auth/route.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { db } from '@/lib/db';
|
||||
|
||||
import { auth, currentUser } from '@clerk/nextjs/server';
|
||||
import { Liveblocks } from '@liveblocks/node';
|
||||
import { headers } from 'next/headers';
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const { sessionClaims } = await auth();
|
||||
const user = await currentUser();
|
||||
if (!sessionClaims || !user) {
|
||||
return new Response('Not authorized', { status: 401 });
|
||||
}
|
||||
|
||||
const { room } = await req.json();
|
||||
const boardId = (await headers()).get('BoardId') as string;
|
||||
const board = await db.board.findUnique({
|
||||
where: {
|
||||
id: boardId,
|
||||
orgId: sessionClaims.org_id,
|
||||
},
|
||||
});
|
||||
if (!board || board.orgId !== sessionClaims.org_id) {
|
||||
return new Response('Not authorized', { status: 401 });
|
||||
}
|
||||
|
||||
const liveblocks = new Liveblocks({
|
||||
secret: process.env.LIVEBLOCKS_SECRET_KEY!,
|
||||
});
|
||||
const session = liveblocks.prepareSession(user.id, {
|
||||
userInfo: {
|
||||
name: user.fullName!,
|
||||
avatar: user.imageUrl,
|
||||
},
|
||||
});
|
||||
session.allow(room, session.FULL_ACCESS);
|
||||
const { body, status } = await session.authorize();
|
||||
|
||||
return new Response(body, { status });
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue