-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
修复了未认证用户能够加入房间的问题,现在后端会检查用户是否经过身份验证,只有在提供有效的Clerk授权标头和存在当前用户的情况下,才会为用户创建Liveblocks会话并允许访问特定房间。此外,更新了`liveblocks.config.ts`中的导出以符合新的认证机制。 BREAKING CHANGE: 依赖于LiveblocksProvider中的`publicApiKey`属性的现有实现将需要移除该属性并迁移到使用新的`authEndpoint`属性,以指向新的认证路由。
- Loading branch information
1 parent
aa11040
commit 8df3029
Showing
5 changed files
with
70 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,49 @@ | ||
import { Liveblocks } from "@liveblocks/node"; | ||
import {liveblocksSCKey} from "@/liveblocks.config"; | ||
import { Liveblocks } from "@liveblocks/node"; | ||
import { liveblocksSCKey } from "@/liveblocks.config"; | ||
|
||
const liveblocksSecretKey= liveblocksSCKey; | ||
import { ConvexHttpClient } from "convex/browser"; | ||
|
||
import { api } from "@/convex/_generated/api"; | ||
import { auth, currentUser } from "@clerk/nextjs/server"; | ||
|
||
const convex = new ConvexHttpClient( | ||
process.env.NEXT_PUBLIC_CONVEX_URL! | ||
); | ||
|
||
const liveblocksSecretKey = liveblocksSCKey; | ||
const liveblocks = new Liveblocks({ | ||
secret: liveblocksSCKey ?? "", | ||
}); | ||
|
||
export async function POST(request: Request) { | ||
const authorization = auth(); | ||
const user = await currentUser(); | ||
|
||
if (!authorization || !user) { | ||
return new Response("Unauthorized", { status: 403 }); | ||
} | ||
|
||
const { room } = await request.json(); // the room we trying to join | ||
const board = await convex.query(api.board.get, { id: room }); | ||
|
||
|
||
if (board?.orgId !== authorization.orgId) { | ||
return new Response("Unauthorized", { status: 403 }); | ||
} | ||
|
||
const userInfo = { | ||
name: user.firstName || "Teammate", | ||
imageUrl: user.imageUrl, | ||
}; | ||
|
||
const session = liveblocks.prepareSession(user.id, { userInfo }); | ||
|
||
if (room) { | ||
session.allow(room, session.FULL_ACCESS); | ||
} | ||
|
||
const { status, body } = await session.authorize(); | ||
|
||
return new Response(body, { status }); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,3 +178,5 @@ export const get = query({ | |
return board; | ||
}, | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters