Fix frontend Docker build and session ID typing

This commit is contained in:
2026-02-20 22:02:48 -05:00
parent 7df3d54103
commit 6e299b1e1f
3 changed files with 17 additions and 9 deletions

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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);
}