Skip to content

Commit

Permalink
enhance custom auth (Chainlit#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
willydouhard authored Dec 28, 2023
1 parent db3f256 commit 9f3fc4d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion backend/chainlit/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand Down
1 change: 1 addition & 0 deletions backend/chainlit/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libs/react-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
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.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",
Expand Down
9 changes: 8 additions & 1 deletion libs/react-client/src/useChatSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,14 @@ const useChatSession = () => {
}
}, [session]);

return { connect, disconnect, chatProfile, idToResume, setChatProfile };
return {
connect,
disconnect,
session,
chatProfile,
idToResume,
setChatProfile
};
};

export { useChatSession };

0 comments on commit 9f3fc4d

Please sign in to comment.