diff --git a/.env.example b/.env.example deleted file mode 100644 index eb99d156..00000000 --- a/.env.example +++ /dev/null @@ -1,137 +0,0 @@ -# =========================================== -# Codeunia Environment Variables -# =========================================== -# Copy this file to .env.local and fill in your actual values - -# =========================================== -# Core Application Settings -# =========================================== -NODE_ENV=development -NEXT_PUBLIC_SITE_URL=http://localhost:3000 - -# =========================================== -# Supabase Configuration -# =========================================== -NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url -NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key -SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key - -# =========================================== -# Authentication & Security -# =========================================== -NEXTAUTH_SECRET=your_nextauth_secret_key -CSRF_SECRET=your_csrf_secret_key - -# =========================================== -# Monitoring & Alerting System -# =========================================== -# Enable/disable alerting system -ALERTING_ENABLED=true - -# Email alerting configuration -ALERT_EMAIL_RECIPIENTS=connect@codeunia.com -RESEND_API_KEY=your_resend_api_key - -# Alert thresholds -ALERT_RESPONSE_TIME_THRESHOLD=5000 -ALERT_ERROR_RATE_THRESHOLD=10 -ALERT_CONSECUTIVE_FAILURES=3 - -# Optional: Webhook URLs for additional alerting -ALERT_WEBHOOK_URL=your_webhook_url -SLACK_WEBHOOK_URL=your_slack_webhook_url -DISCORD_WEBHOOK_URL=your_discord_webhook_url - -# =========================================== -# Database & Caching -# =========================================== -# Redis configuration for caching -REDIS_URL=redis://localhost:6379 - -# =========================================== -# Payment Integration -# =========================================== -# Razorpay configuration -RAZORPAY_KEY_ID=your_razorpay_key_id -RAZORPAY_KEY_SECRET=your_razorpay_key_secret - -# =========================================== -# AI Integration -# =========================================== -# OpenRouter API for AI features -OPENROUTER_API_KEY=your_openrouter_api_key - -# =========================================== -# SEO & Analytics -# =========================================== -# Search engine verification codes -GOOGLE_SITE_VERIFICATION=your_google_verification_code -BING_VERIFICATION=your_bing_verification_code -YANDEX_VERIFICATION=your_yandex_verification_code -YAHOO_VERIFICATION=your_yahoo_verification_code - -# =========================================== -# Build & Deployment -# =========================================== -# Vercel deployment -VERCEL_URL=your_vercel_url -VERCEL_GIT_COMMIT_SHA=your_git_commit_sha - -# GitHub Actions -GITHUB_SHA=your_github_sha - -# Build configuration -BUILD_ID=your_build_id -ANALYZE=false - -# =========================================== -# Development & Testing -# =========================================== -# Puppeteer configuration -PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true -PUPPETEER_CACHE_DIR=/tmp/.cache/puppeteer - -# Node.js memory configuration -NODE_OPTIONS=--max-old-space-size=4096 - -# =========================================== -# Security & Rate Limiting -# =========================================== -# Rate limiting configuration -RATE_LIMIT_ENABLED=true -RATE_LIMIT_MAX_REQUESTS=100 -RATE_LIMIT_WINDOW_MS=900000 - -# =========================================== -# Optional: Third-party Services -# =========================================== -# Cloudflare (if using Cloudflare for caching) -CLOUDFLARE_API_TOKEN=your_cloudflare_api_token -CLOUDFLARE_ZONE_ID=your_cloudflare_zone_id - -# =========================================== -# Production-specific Settings -# =========================================== -# Uncomment and configure for production -# NODE_ENV=production -# NEXT_PUBLIC_SITE_URL=https://your-domain.com -# ALERTING_ENABLED=true -# REDIS_URL=redis://your-production-redis-url - -# =========================================== -# CI/CD & Testing -# =========================================== -# Test environment URLs -STAGING_URL=https://your-staging-url.vercel.app -PRODUCTION_URL=https://your-production-url.vercel.app - -# Lighthouse CI -LHCI_GITHUB_APP_TOKEN=your_lighthouse_ci_token - -# Codecov -CODECOV_TOKEN=your_codecov_token - -# Vercel deployment tokens (for GitHub Actions) -VERCEL_TOKEN=your_vercel_token -VERCEL_ORG_ID=your_vercel_org_id -VERCEL_PROJECT_ID=your_vercel_project_id diff --git a/app/auth/callback/page.tsx b/app/auth/callback/page.tsx index a9270f02..2ad7fbcb 100644 --- a/app/auth/callback/page.tsx +++ b/app/auth/callback/page.tsx @@ -4,6 +4,7 @@ import { useEffect, Suspense } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import { createClient } from "@/lib/supabase/client"; import { toast } from "sonner"; +import { profileService } from "@/lib/services/profile"; function OAuthCallbackContent() { const router = useRouter(); @@ -38,19 +39,18 @@ function OAuthCallbackContent() { .single(); if (!profile) { - // Create profile for OAuth user - const provider = session.user.app_metadata?.provider || 'google'; - await supabase.rpc('create_oauth_profile', { - user_id: session.user.id, - email: session.user.email || '', - auth_provider: provider, - user_metadata: session.user.user_metadata || {} - }); - - // After creating profile, redirect to complete profile - console.log('Profile created, redirecting to complete profile'); - router.replace('/complete-profile'); - return; + // Create profile for OAuth user using profileService + try { + await profileService.getProfile(session.user.id); + console.log('Profile created via profileService, redirecting to complete profile'); + router.replace('/complete-profile'); + return; + } catch (profileError) { + console.error('Error creating profile:', profileError); + // Continue to complete profile page anyway + router.replace('/complete-profile'); + return; + } } // Check if profile is complete (has first_name, last_name, and username) @@ -115,19 +115,18 @@ function OAuthCallbackContent() { .single(); if (!profile) { - // Create profile for OAuth user - const provider = retrySession.user.app_metadata?.provider || 'google'; - await supabase.rpc('create_oauth_profile', { - user_id: retrySession.user.id, - email: retrySession.user.email || '', - auth_provider: provider, - user_metadata: retrySession.user.user_metadata || {} - }); - - // After creating profile, redirect to complete profile - console.log('Profile created on retry, redirecting to complete profile'); - router.replace('/complete-profile'); - return; + // Create profile for OAuth user using profileService + try { + await profileService.getProfile(retrySession.user.id); + console.log('Profile created via profileService on retry, redirecting to complete profile'); + router.replace('/complete-profile'); + return; + } catch (profileError) { + console.error('Error creating profile on retry:', profileError); + // Continue to complete profile page anyway + router.replace('/complete-profile'); + return; + } } // Check if profile is complete (has first_name, last_name, and username) @@ -167,19 +166,18 @@ function OAuthCallbackContent() { .single(); if (!profile) { - // Create profile for OAuth user - const provider = finalSession.user.app_metadata?.provider || 'google'; - await supabase.rpc('create_oauth_profile', { - user_id: finalSession.user.id, - email: finalSession.user.email || '', - auth_provider: provider, - user_metadata: finalSession.user.user_metadata || {} - }); - - // After creating profile, redirect to complete profile - console.log('Profile created on final try, redirecting to complete profile'); - router.replace('/complete-profile'); - return; + // Create profile for OAuth user using profileService + try { + await profileService.getProfile(finalSession.user.id); + console.log('Profile created via profileService on final try, redirecting to complete profile'); + router.replace('/complete-profile'); + return; + } catch (profileError) { + console.error('Error creating profile on final try:', profileError); + // Continue to complete profile page anyway + router.replace('/complete-profile'); + return; + } } // Check if profile is complete (has first_name, last_name, and username)