Fix frontend Docker build and session ID typing
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user