fixed claude login

This commit is contained in:
2026-03-12 02:19:31 +01:00
parent 5e2b31385f
commit ac1e5c332f
3 changed files with 80 additions and 16 deletions
+46 -15
View File
@@ -475,6 +475,14 @@ function dockerExecStreaming(containerName, cmd, onData, onEnd) {
createReq.end();
}
function stripAnsi(str) {
// ANSI escape sequences entfernen (Farben, Cursor, etc.)
return str.replace(/\x1b\[[0-9;?]*[a-zA-Z]/g, "")
.replace(/\x1b\][^\x07]*\x07/g, "")
.replace(/\x1b[><=][0-9]*/g, "")
.replace(/[\x00-\x08\x0e-\x1f]/g, "");
}
function startProxyLogin() {
if (loginProcess) {
log("warn", "proxy", "Login laeuft bereits");
@@ -485,26 +493,20 @@ function startProxyLogin() {
log("info", "proxy", "Starte Claude Login im Proxy-Container...");
broadcast({ type: "login_status", status: "starting" });
// Volume ist :ro — wir muessen es rw remounten oder direkt im Container schreiben
// Da das Volume ro ist, schreiben wir die Credentials in einen temp-Pfad und kopieren sie danach
// Einfacher: claude login schreibt nach /root/.config/claude/ — das ist das gemountete Volume
// Problem: Volume ist :ro! Login kann nicht schreiben.
// Loesung: Login OHNE Volume ausfuehren, dann Credentials rauskopieren
// Alternative: Wir machen es anders — Login direkt, Output streamen
// claude login: --no-open verhindert Browser-Oeffnung (Container hat keinen)
// Fallback auf verschiedene CLI-Versionen
dockerExecStreaming("aria-proxy", "claude login 2>&1 || echo 'Login-Befehl fehlgeschlagen. claude --version:' && claude --version 2>&1",
// TERM=dumb und NO_COLOR=1 deaktivieren die TUI und Farben
dockerExecStreaming("aria-proxy", "TERM=dumb NO_COLOR=1 CI=1 claude login 2>&1",
(chunk) => {
// Jeder Chunk wird live an die UI gesendet
log("info", "proxy", `[login] ${chunk.trim()}`);
const clean = stripAnsi(chunk).trim();
if (!clean) return;
log("info", "proxy", `[login] ${clean}`);
// URLs erkennen und hervorheben
const urlMatch = chunk.match(/https?:\/\/[^\s\]]+/);
const urlMatch = clean.match(/https?:\/\/[^\s\]]+/);
if (urlMatch) {
broadcast({ type: "login_url", url: urlMatch[0], raw: chunk.trim() });
broadcast({ type: "login_url", url: urlMatch[0], raw: clean });
} else {
broadcast({ type: "login_output", text: chunk.trim() });
broadcast({ type: "login_output", text: clean });
}
},
(err) => {
@@ -522,6 +524,33 @@ function startProxyLogin() {
);
}
// Credentials manuell einfuegen (von einem Rechner wo Claude eingeloggt ist)
async function writeProxyCredentials(credentialsJson) {
try {
// Validieren
const parsed = JSON.parse(credentialsJson);
if (!parsed.claudeAiOauth && !parsed.oauth) {
throw new Error("Ungueltig: Kein OAuth-Objekt gefunden. Erwartet 'claudeAiOauth' oder 'oauth' Key.");
}
log("info", "proxy", "Schreibe Credentials in Proxy-Container...");
// Escaped fuer Shell — Einfache Anfuehrungszeichen im JSON escapen
const escaped = credentialsJson.replace(/'/g, "'\\''");
await dockerExec("aria-proxy", `mkdir -p /root/.config/claude && echo '${escaped}' > /root/.config/claude/.credentials.json`);
log("info", "proxy", "Credentials geschrieben!");
broadcast({ type: "login_status", status: "done" });
broadcast({ type: "login_output", text: "Credentials erfolgreich geschrieben! Proxy muss neu gestartet werden." });
// Auth pruefen
setTimeout(() => checkProxyAuth(), 500);
} catch (err) {
log("error", "proxy", `Credentials schreiben fehlgeschlagen: ${err.message}`);
broadcast({ type: "login_status", status: "error", error: err.message });
}
}
async function checkProxyAuth() {
try {
log("info", "proxy", "Pruefe Auth-Dateien im Proxy-Container...");
@@ -709,6 +738,8 @@ wss.on("connection", (ws) => {
checkProxyAuth();
} else if (msg.action === "proxy_login") {
startProxyLogin();
} else if (msg.action === "write_credentials") {
writeProxyCredentials(msg.credentials);
} else if (msg.action === "docker_logs") {
handleDockerLogs(ws, msg.tab, msg.tail);
}