Skip to content

Commit

Permalink
disable jwt auth for elements (#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
willydouhard authored Jan 6, 2024
1 parent e86657e commit ac9dbdb
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 22 deletions.
8 changes: 0 additions & 8 deletions backend/chainlit/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,6 @@ async def upload_file(
async def get_file(
file_id: str,
session_id: Optional[str] = None,
token: Optional[str] = None,
):
from chainlit.session import WebsocketSession

Expand All @@ -611,13 +610,6 @@ async def get_file(
detail="Session not found",
)

if current_user := await get_current_user(token or ""):
if not session.user or session.user.identifier != current_user.identifier:
raise HTTPException(
status_code=401,
detail="You are not authorized to upload files for this session",
)

if file_id in session.files:
file = session.files[file_id]
return FileResponse(file["path"], media_type=file["type"])
Expand Down
2 changes: 1 addition & 1 deletion libs/react-client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@chainlit/react-client",
"description": "Websocket client to connect to your chainlit app.",
"version": "0.0.4",
"version": "0.0.5",
"scripts": {
"build": "tsup src/index.ts --clean --format esm,cjs --dts --external react --external recoil --minify --sourcemap --treeshake",
"dev": "tsup src/index.ts --clean --format esm,cjs --dts --external react --external recoil --minify --sourcemap --treeshake",
Expand Down
10 changes: 2 additions & 8 deletions libs/react-client/src/api/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,8 @@ export class ChainlitAPI extends APIBase {
return { xhr, promise };
}

getElementUrl(id: string, sessionId: string, accessToken?: string) {
let queryParams = `?session_id=${sessionId}`;
if (accessToken) {
if (accessToken.startsWith('Bearer ')) {
accessToken = accessToken.slice(7);
}
queryParams += `&token=${accessToken}`;
}
getElementUrl(id: string, sessionId: string) {
const queryParams = `?session_id=${sessionId}`;
return this.buildEndpoint(`/project/file/${id}${queryParams}`);
}

Expand Down
6 changes: 1 addition & 5 deletions libs/react-client/src/useChatSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,7 @@ const useChatSession = () => {

socket.on('element', (element: IElement) => {
if (!element.url && element.chainlitKey) {
element.url = client.getElementUrl(
element.chainlitKey,
sessionId,
accessToken
);
element.url = client.getElementUrl(element.chainlitKey, sessionId);
}

if (element.type === 'avatar') {
Expand Down

0 comments on commit ac9dbdb

Please sign in to comment.