diff --git a/src/components/ui/toast.tsx b/src/components/ui/toast.tsx index a8224775..38fdfa25 100644 --- a/src/components/ui/toast.tsx +++ b/src/components/ui/toast.tsx @@ -14,7 +14,7 @@ const ToastViewport = React.forwardRef< , React.ComponentPropsWithoutRef & - VariantProps + VariantProps >(({ className, variant, ...props }, ref) => { return ( { // Initialize with first recently used model if available, otherwise empty return settings.recentlyUsedModels?.[0] || ''; @@ -41,6 +45,48 @@ export default function Index() { // Check if any providers are configured const hasProvidersConfigured = settings.providers.length > 0; + // Check for API key failures and show appropriate toast + const checkForKeyFailure = (error: unknown): boolean => { + if (!(error instanceof Error)) return false; + + const message = error.message.toLowerCase(); + const isAuthError = ( + message.includes('401') || + message.includes('unauthorized') || + message.includes('no auth credentials') || + message.includes('invalid api key') || + message.includes('authentication failed') + ); + + if (isAuthError) { + // Get provider name inline + let providerName = 'Provider'; + try { + const { provider } = parseProviderModel(providerModel, settings.providers); + providerName = provider.charAt(0).toUpperCase() + provider.slice(1); + } catch { + // Keep default 'Provider' + } + + toast({ + title: t('apiAuthenticationFailed'), + description: t('invalidApiKey', { provider: providerName }), + variant: 'destructive', + action: ( + navigate('/settings/ai')} + > + {t('checkApiKeySettings')} + + ), + }); + } + + return isAuthError; + }; + + useEffect(() => { if (!providerModel && settings.recentlyUsedModels?.length) { setProviderModel(settings.recentlyUsedModels[0]); @@ -185,6 +231,7 @@ export default function Index() { navigate(`/project/${project.id}?${searchParams.toString()}`); } catch (error) { console.error('Failed to create project:', error); + checkForKeyFailure(error); } finally { setIsCreating(false); } @@ -209,9 +256,8 @@ export default function Index() {
{/* Chat Input Container - matching the ChatPane style */}