Files
opencode-manager/frontend/src/lib/oauthErrors.ts
T
Chris Scott 3f9c398b31 feat: MCP OAuth flow improvements (#123)
Rewrite OAuth flow handle authentication entirely in web app with secure proxy
- Add MCP OAuth proxy with origin validation and callback handling
- Remove auto OAuth method from authentication flow
- Fix TypeScript build errors
- Add directory support for MCP OAuth flows and improve config manager UI
- Reload session caches after MCP connection changes
2026-02-13 00:10:56 -05:00

31 lines
1.1 KiB
TypeScript

export const OAuthMethod = {
CODE: 0,
} as const
export type OAuthMethodType = (typeof OAuthMethod)[keyof typeof OAuthMethod]
const ERROR_MAPPINGS: Record<string, string> = {
'invalid code': 'Invalid authorization code. Please try the OAuth flow again.',
'expired': 'Authorization code has expired. Please try the OAuth flow again.',
'access denied': 'Access was denied. Please check the permissions and try again.',
'server error': 'Server error occurred. Please try again later.',
'provider not found': 'Provider is not available or does not support OAuth.',
'invalid method': 'Invalid authentication method selected.',
}
export function mapOAuthError(err: unknown, context: 'authorize' | 'callback'): string {
const defaultMessage = context === 'authorize'
? 'Failed to initiate OAuth authorization'
: 'Failed to complete OAuth callback'
if (!(err instanceof Error)) return defaultMessage
for (const [key, message] of Object.entries(ERROR_MAPPINGS)) {
if (err.message.toLowerCase().includes(key)) {
return message
}
}
return err.message || defaultMessage
}