Enhance logout to clear MCP OAuth tokens and disconnect all servers

## Problem
The logout button only cleared inference provider authentication, leaving
MCP OAuth tokens and server connections active. Users remained authenticated
to MCP servers after logging out.

## Solution
- **Clear MCP OAuth tokens**: Remove OAuth tokens and state for all MCP connections
- **Disconnect all servers**: Remove all MCP server connections on logout
- **Complete cleanup**: Comprehensive logout that clears all authentication state
- **Enhanced confirmation**: Updated dialog to inform users about MCP disconnection

## Technical Implementation
- Added MCP context integration to access connections and removal methods
- Clear OAuth tokens from localStorage for each OAuth-enabled connection
- Remove all MCP servers to properly disconnect and clean up connections
- Maintained existing inference provider logout functionality

## User Experience
- ✅ **Complete logout**: All authentication state cleared (inference + MCP)
- ✅ **Clean slate**: No residual authentication data after logout
- ✅ **Clear communication**: User informed about full scope of logout action
- ✅ **Security**: No orphaned authentication tokens left behind

## Data Cleared on Logout
- Inference provider API keys and OAuth tokens
- MCP OAuth tokens and authentication state
- Model selection preferences
- All active MCP server connections

Note: Conversation history remains intact as it's stored separately from auth data.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jerome 2025-06-12 15:04:08 +01:00
commit 253db5ebc1
No known key found for this signature in database

View file

@ -2,6 +2,7 @@
import { useConversation } from '@/contexts/ConversationContext';
import { useInference } from '@/contexts/InferenceContext';
import { useMCP } from '@/contexts/MCPContext';
export function ConversationSidebar() {
const {
@ -13,14 +14,30 @@ export function ConversationSidebar() {
} = useConversation();
const { clearProvider, provider } = useInference();
const { connections, removeMcpServer } = useMCP();
const handleNewConversation = () => {
createConversation();
};
const handleLogout = () => {
if (confirm('Are you sure you want to log out?')) {
if (confirm('Are you sure you want to log out? This will disconnect all MCP servers and clear your authentication.')) {
// Clear inference provider authentication
clearProvider();
// Clear MCP OAuth tokens for all connections
connections.forEach(connection => {
if (connection.authType === 'oauth') {
// Clear OAuth tokens and state for this connection
localStorage.removeItem(`mcp_oauth_tokens_${connection.id}`);
localStorage.removeItem(`mcp_oauth_state_${connection.id}`);
}
});
// Remove all MCP servers (this will disconnect them)
connections.forEach(connection => {
removeMcpServer(connection.id);
});
}
};