Fix project isolation: Make loadChatHistory respect active project sessions
- Modified loadChatHistory() to check for active project before fetching all sessions - When active project exists, use project.sessions instead of fetching from API - Added detailed console logging to debug session filtering - This prevents ALL sessions from appearing in every project's sidebar Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
65
auth-improvements.js
Normal file
65
auth-improvements.js
Normal file
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Improved Authentication Middleware
|
||||
* Add this to server.js to provide better error messages
|
||||
*/
|
||||
|
||||
// Enhanced authentication middleware with helpful error messages
|
||||
function requireAuth(req, res, next) {
|
||||
if (req.session.userId) {
|
||||
next();
|
||||
} else {
|
||||
// Provide helpful error message with login URL
|
||||
res.status(401).json({
|
||||
error: 'Authentication required',
|
||||
message: 'You must be logged in to access this resource',
|
||||
loginUrl: '/claude/login.html',
|
||||
authenticated: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Optional authentication - doesn't fail, just attaches auth status to request
|
||||
function optionalAuth(req, res, next) {
|
||||
req.isAuthenticated = !!req.session.userId;
|
||||
req.userId = req.session.userId;
|
||||
next();
|
||||
}
|
||||
|
||||
// Health check endpoint (add to server.js after auth middleware)
|
||||
/*
|
||||
app.get('/api/health', optionalAuth, (req, res) => {
|
||||
res.json({
|
||||
status: 'ok',
|
||||
server: 'obsidian-web-interface',
|
||||
version: '1.0.0',
|
||||
authenticated: req.isAuthenticated,
|
||||
userId: req.userId || null,
|
||||
websocket: {
|
||||
url: 'ws://localhost:3010/claude/api/claude/chat',
|
||||
status: 'running'
|
||||
},
|
||||
endpoints: {
|
||||
projects: '/claude/api/claude/projects',
|
||||
sessions: '/claude/api/claude/sessions',
|
||||
login: '/claude/api/login',
|
||||
logout: '/claude/api/logout'
|
||||
},
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
// Debug endpoint to check current auth status
|
||||
/*
|
||||
app.get('/api/auth/debug', optionalAuth, (req, res) => {
|
||||
res.json({
|
||||
authenticated: req.isAuthenticated,
|
||||
userId: req.userId,
|
||||
sessionID: req.sessionID,
|
||||
cookie: req.headers.cookie ? 'present' : 'missing',
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
module.exports = { requireAuth, optionalAuth };
|
||||
Reference in New Issue
Block a user