mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-06-01 09:55:34 +08:00
fix: refresh Claude auth status after login flow (#617)
* fix: refresh Claude auth status after login flow * fix: rely on refreshed auth status after login --------- Co-authored-by: HolyCode User <noreply@holycode.local>
This commit is contained in:
@@ -16,6 +16,10 @@ type ClaudeCredentialsStatus = {
|
||||
error?: string;
|
||||
};
|
||||
|
||||
const hasErrorCode = (error: unknown, code: string): boolean => (
|
||||
error instanceof Error && 'code' in error && error.code === code
|
||||
);
|
||||
|
||||
export class ClaudeProviderAuth implements IProviderAuth {
|
||||
/**
|
||||
* Checks whether the Claude Code CLI is available on this host.
|
||||
@@ -77,6 +81,8 @@ export class ClaudeProviderAuth implements IProviderAuth {
|
||||
* Checks Claude credentials in the same priority order used by Claude Code.
|
||||
*/
|
||||
private async checkCredentials(): Promise<ClaudeCredentialsStatus> {
|
||||
const missingCredentialsError = 'Claude CLI is not authenticated. Run claude /login or configure ANTHROPIC_API_KEY.';
|
||||
|
||||
if (process.env.ANTHROPIC_API_KEY?.trim()) {
|
||||
return { authenticated: true, email: 'API Key Auth', method: 'api_key' };
|
||||
}
|
||||
@@ -110,15 +116,33 @@ export class ClaudeProviderAuth implements IProviderAuth {
|
||||
|
||||
return {
|
||||
authenticated: false,
|
||||
email,
|
||||
method: 'credentials_file',
|
||||
error: 'OAuth token has expired. Please re-authenticate with claude login',
|
||||
email: null,
|
||||
method: null,
|
||||
error: 'Claude login has expired. Run claude /login again.',
|
||||
};
|
||||
}
|
||||
|
||||
return { authenticated: false, email: null, method: null };
|
||||
} catch {
|
||||
return { authenticated: false, email: null, method: null };
|
||||
return {
|
||||
authenticated: false,
|
||||
email: null,
|
||||
method: null,
|
||||
error: missingCredentialsError,
|
||||
};
|
||||
} catch (error) {
|
||||
let errorMessage = 'Unable to read Claude credentials. Run claude /login again.';
|
||||
|
||||
if (hasErrorCode(error, 'ENOENT')) {
|
||||
errorMessage = missingCredentialsError;
|
||||
} else if (error instanceof SyntaxError) {
|
||||
errorMessage = 'Claude credentials are unreadable. Run claude /login again.';
|
||||
}
|
||||
|
||||
return {
|
||||
authenticated: false,
|
||||
email: null,
|
||||
method: null,
|
||||
error: errorMessage,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user