|
6 | 6 | */ |
7 | 7 | import { useState, useCallback, useEffect } from 'react'; |
8 | 8 | import axios, { AxiosResponse } from 'axios'; |
| 9 | +import { useAuth } from '@clerk/nextjs'; |
9 | 10 | import { showToast } from '@/lib/toast'; |
10 | 11 | import { PostQueuePanel } from './PostQueuePanel'; |
11 | 12 | import { ImageSelector } from './ImageSelector'; |
@@ -84,6 +85,7 @@ const AI_MODELS = [ |
84 | 85 | ]; |
85 | 86 |
|
86 | 87 | export function BotModePanel({ userId, postsRemaining = 10, tier = 'free', isLimitReached = false }: BotModePanelProps) { |
| 88 | + const { getToken } = useAuth(); |
87 | 89 |
|
88 | 90 | // State |
89 | 91 | const [activities, setActivities] = useState<Activity[]>([]); |
@@ -127,10 +129,13 @@ export function BotModePanel({ userId, postsRemaining = 10, tier = 'free', isLim |
127 | 129 |
|
128 | 130 | try { |
129 | 131 | const hours = searchDays * 24; |
| 132 | + const token = await getToken(); |
130 | 133 | const response = await axios.post(`${API_BASE}/api/github/scan`, { |
131 | 134 | user_id: userId, |
132 | 135 | hours: hours, |
133 | 136 | activity_type: activityType !== 'all' ? activityType : undefined |
| 137 | + }, { |
| 138 | + headers: { Authorization: `Bearer ${token}` } |
134 | 139 | }); |
135 | 140 |
|
136 | 141 | if (response.data.error) { |
@@ -181,10 +186,13 @@ export function BotModePanel({ userId, postsRemaining = 10, tier = 'free', isLim |
181 | 186 | const toastId = showToast.loading(`Generating ${toGenerate.length} posts...`); |
182 | 187 |
|
183 | 188 | try { |
| 189 | + const token = await getToken(); |
184 | 190 | const response = await axios.post(`${API_BASE}/api/post/generate-batch`, { |
185 | 191 | user_id: userId, |
186 | 192 | activities: toGenerate, |
187 | 193 | style: selectedTemplate |
| 194 | + }, { |
| 195 | + headers: { Authorization: `Bearer ${token}` } |
188 | 196 | }); |
189 | 197 |
|
190 | 198 | showToast.dismiss(toastId); |
@@ -273,11 +281,14 @@ export function BotModePanel({ userId, postsRemaining = 10, tier = 'free', isLim |
273 | 281 | setPublishingId(postId); |
274 | 282 |
|
275 | 283 | try { |
| 284 | + const token = await getToken(); |
276 | 285 | const response = await axios.post(`${API_BASE}/api/publish/full`, { |
277 | 286 | user_id: userId, |
278 | 287 | post_content: post.content, |
279 | 288 | image_url: post.image_url, |
280 | 289 | test_mode: testMode |
| 290 | + }, { |
| 291 | + headers: { Authorization: `Bearer ${token}` } |
281 | 292 | }); |
282 | 293 |
|
283 | 294 | if (response.data.error) { |
|
0 commit comments