diff --git a/frontend/Dockerfile b/frontend/Dockerfile index e7b1096..aba4604 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -11,7 +11,7 @@ RUN npm install FROM base AS builder COPY --from=deps /app/node_modules ./node_modules COPY . . -RUN npm run build +RUN mkdir -p public && npm run build # Production FROM base AS runner diff --git a/frontend/app/portfolio/page.tsx b/frontend/app/portfolio/page.tsx index d9c2763..22663c3 100644 --- a/frontend/app/portfolio/page.tsx +++ b/frontend/app/portfolio/page.tsx @@ -22,7 +22,7 @@ export default function PortfolioPage() { return; } - if (session?.user) { + if (session?.user?.id) { fetchPortfolio(session.user.id); } }, [session, isPending, router]); @@ -48,13 +48,15 @@ export default function PortfolioPage() { const handleAddHolding = async (e: React.FormEvent) => { e.preventDefault(); + const userId = session?.user?.id; + if (!userId) return; try { await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/portfolio`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ - user_id: session?.user?.id, + user_id: userId, ticker: newHolding.ticker.toUpperCase(), shares: parseFloat(newHolding.shares), avg_cost: parseFloat(newHolding.avg_cost) @@ -63,7 +65,7 @@ export default function PortfolioPage() { setShowAddModal(false); setNewHolding({ ticker: '', shares: '', avg_cost: '' }); - fetchPortfolio(session?.user?.id); + fetchPortfolio(userId); } catch (error) { console.error('Error adding holding:', error); } @@ -71,13 +73,15 @@ export default function PortfolioPage() { const handleDeleteHolding = async (id: number) => { if (!confirm('Are you sure you want to delete this holding?')) return; + const userId = session?.user?.id; + if (!userId) return; try { await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/portfolio/${id}`, { method: 'DELETE' }); - fetchPortfolio(session?.user?.id); + fetchPortfolio(userId); } catch (error) { console.error('Error deleting holding:', error); } diff --git a/frontend/app/watchlist/page.tsx b/frontend/app/watchlist/page.tsx index dbd06ab..c351d0f 100644 --- a/frontend/app/watchlist/page.tsx +++ b/frontend/app/watchlist/page.tsx @@ -19,7 +19,7 @@ export default function WatchlistPage() { return; } - if (session?.user) { + if (session?.user?.id) { fetchWatchlist(session.user.id); } }, [session, isPending, router]); @@ -38,13 +38,15 @@ export default function WatchlistPage() { const handleAddStock = async (e: React.FormEvent) => { e.preventDefault(); + const userId = session?.user?.id; + if (!userId) return; try { await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/watchlist`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ - user_id: session?.user?.id, + user_id: userId, ticker: newStock.ticker.toUpperCase(), company_name: newStock.company_name, sector: newStock.sector @@ -53,7 +55,7 @@ export default function WatchlistPage() { setShowAddModal(false); setNewStock({ ticker: '', company_name: '', sector: '' }); - fetchWatchlist(session?.user?.id); + fetchWatchlist(userId); } catch (error) { console.error('Error adding stock:', error); } @@ -61,13 +63,15 @@ export default function WatchlistPage() { const handleDeleteStock = async (id: number) => { if (!confirm('Are you sure you want to remove this stock from watchlist?')) return; + const userId = session?.user?.id; + if (!userId) return; try { await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/watchlist/${id}`, { method: 'DELETE' }); - fetchWatchlist(session?.user?.id); + fetchWatchlist(userId); } catch (error) { console.error('Error deleting stock:', error); }