mirror of
https://github.com/ahmadk953/tasko.git
synced 2025-05-01 11:19:34 +00:00
Started Adding Liveblocks
This commit is contained in:
parent
cde7e7ab6e
commit
03dd8df0f1
4 changed files with 248 additions and 3 deletions
26
app/api/liveblocks-auth/route.ts
Normal file
26
app/api/liveblocks-auth/route.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { Liveblocks } from '@liveblocks/node';
|
||||
import { useUser, auth } from '@clerk/nextjs';
|
||||
|
||||
const liveblocks = new Liveblocks({
|
||||
secret: process.env.LIVEBLOCKS_SECRET_DEV_API_KEY!,
|
||||
});
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const { user } = useUser();
|
||||
const { orgId } = auth();
|
||||
|
||||
if (!orgId || !user) return new Response('Unauthorized', { status: 401 });
|
||||
|
||||
// Start an auth session inside your endpoint
|
||||
const session = liveblocks.prepareSession(user.id);
|
||||
|
||||
// Implement your own security, and give the user access to the room
|
||||
const { room } = await req.json();
|
||||
if (room) {
|
||||
session.allow(room, session.FULL_ACCESS);
|
||||
}
|
||||
|
||||
// Authorize the user and return the result
|
||||
const { status, body } = await session.authorize();
|
||||
return new Response(body, { status });
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue