diff --git a/backend/chainlit/auth.py b/backend/chainlit/auth.py index 0812d5dba2..5a9bd70a77 100644 --- a/backend/chainlit/auth.py +++ b/backend/chainlit/auth.py @@ -30,7 +30,8 @@ def is_oauth_enabled(): def require_login(): return ( - config.code.password_auth_callback is not None + bool(os.environ.get("CHAINLIT_CUSTOM_AUTH")) + or config.code.password_auth_callback is not None or config.code.header_auth_callback is not None or is_oauth_enabled() ) diff --git a/backend/chainlit/socket.py b/backend/chainlit/socket.py index 76ec9c8533..339e6e7f1a 100644 --- a/backend/chainlit/socket.py +++ b/backend/chainlit/socket.py @@ -89,6 +89,7 @@ async def connect(sid, environ, auth): token = authorization_header.split(" ")[1] if authorization_header else None user = await get_current_user(token=token) except Exception as e: + logger.info("Authentication failed") return False # Function to send a message to this particular session diff --git a/libs/react-client/README.md b/libs/react-client/README.md index 5c46baa39a..6f056c875e 100644 --- a/libs/react-client/README.md +++ b/libs/react-client/README.md @@ -57,7 +57,7 @@ const ChatComponent = () => { userEnv: { /* user environment variables */ }, - accessToken: 'YOUR_ACCESS_TOKEN' // Optional Chainlit auth token + accessToken: 'Bearer YOUR_ACCESS_TOKEN' // Optional Chainlit auth token }); return () => { diff --git a/libs/react-client/package.json b/libs/react-client/package.json index f1ef626424..cbb4b8b7cc 100644 --- a/libs/react-client/package.json +++ b/libs/react-client/package.json @@ -1,7 +1,7 @@ { "name": "@chainlit/react-client", "description": "Websocket client to connect to your chainlit app.", - "version": "0.0.2", + "version": "0.0.3", "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", diff --git a/libs/react-client/src/useChatSession.ts b/libs/react-client/src/useChatSession.ts index 862c3ca43a..29266870b0 100644 --- a/libs/react-client/src/useChatSession.ts +++ b/libs/react-client/src/useChatSession.ts @@ -265,7 +265,14 @@ const useChatSession = () => { } }, [session]); - return { connect, disconnect, chatProfile, idToResume, setChatProfile }; + return { + connect, + disconnect, + session, + chatProfile, + idToResume, + setChatProfile + }; }; export { useChatSession };