Files
claudecodeui/server/routes/cli-auth.js
Haileyesus 32dfd27156 refactor(providers): move auth status checks into provider runtimes
Move provider authentication status logic out of the CLI auth route so auth checks
live with the provider implementations that understand each provider's install
and credential model.

Add provider-specific auth runtime classes for Claude, Codex, Cursor, and Gemini,
and expose them through the shared provider contract as `provider.auth`. Add a
provider auth service that resolves providers through the registry and delegates
status checks via `auth.getStatus()`.

Keep the existing `/api/cli/<provider>/status` endpoints, but make them thin route
adapters over the new provider auth service. This removes duplicated route-local
credential parsing and makes auth status a first-class provider capability beside
MCP and message handling.
2026-04-17 15:15:26 +03:00

36 lines
1.2 KiB
JavaScript

import express from 'express';
import { providerAuthService } from '../modules/providers/services/provider-auth.service.js';
const router = express.Router();
/**
* Creates a status route handler for one provider while preserving the existing
* /api/cli/<provider>/status endpoint shape.
*/
function createProviderStatusHandler(providerName) {
return async (req, res) => {
try {
const status = await providerAuthService.getProviderAuthStatus(providerName);
return res.json(status);
} catch (error) {
console.error(`Error checking ${providerName} auth status:`, error);
return res.status(500).json({
installed: false,
provider: providerName,
authenticated: false,
email: null,
method: null,
error: error instanceof Error ? error.message : 'Failed to check provider auth status',
});
}
};
}
router.get('/claude/status', createProviderStatusHandler('claude'));
router.get('/cursor/status', createProviderStatusHandler('cursor'));
router.get('/codex/status', createProviderStatusHandler('codex'));
router.get('/gemini/status', createProviderStatusHandler('gemini'));
export default router;