Skip to content

Commit bf9b5dd

Browse files
committed
fix: Add auth tokens to BotModePanel API calls
Added Clerk useAuth hook and Authorization Bearer headers to: - GitHub scan endpoint - Post generate-batch endpoint - Publish/full endpoint This fixes 401 errors after database wipe/fresh start.
1 parent a133dec commit bf9b5dd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

web/src/components/dashboard/BotModePanel.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
import { useState, useCallback, useEffect } from 'react';
88
import axios, { AxiosResponse } from 'axios';
9+
import { useAuth } from '@clerk/nextjs';
910
import { showToast } from '@/lib/toast';
1011
import { PostQueuePanel } from './PostQueuePanel';
1112
import { ImageSelector } from './ImageSelector';
@@ -84,6 +85,7 @@ const AI_MODELS = [
8485
];
8586

8687
export function BotModePanel({ userId, postsRemaining = 10, tier = 'free', isLimitReached = false }: BotModePanelProps) {
88+
const { getToken } = useAuth();
8789

8890
// State
8991
const [activities, setActivities] = useState<Activity[]>([]);
@@ -127,10 +129,13 @@ export function BotModePanel({ userId, postsRemaining = 10, tier = 'free', isLim
127129

128130
try {
129131
const hours = searchDays * 24;
132+
const token = await getToken();
130133
const response = await axios.post(`${API_BASE}/api/github/scan`, {
131134
user_id: userId,
132135
hours: hours,
133136
activity_type: activityType !== 'all' ? activityType : undefined
137+
}, {
138+
headers: { Authorization: `Bearer ${token}` }
134139
});
135140

136141
if (response.data.error) {
@@ -181,10 +186,13 @@ export function BotModePanel({ userId, postsRemaining = 10, tier = 'free', isLim
181186
const toastId = showToast.loading(`Generating ${toGenerate.length} posts...`);
182187

183188
try {
189+
const token = await getToken();
184190
const response = await axios.post(`${API_BASE}/api/post/generate-batch`, {
185191
user_id: userId,
186192
activities: toGenerate,
187193
style: selectedTemplate
194+
}, {
195+
headers: { Authorization: `Bearer ${token}` }
188196
});
189197

190198
showToast.dismiss(toastId);
@@ -273,11 +281,14 @@ export function BotModePanel({ userId, postsRemaining = 10, tier = 'free', isLim
273281
setPublishingId(postId);
274282

275283
try {
284+
const token = await getToken();
276285
const response = await axios.post(`${API_BASE}/api/publish/full`, {
277286
user_id: userId,
278287
post_content: post.content,
279288
image_url: post.image_url,
280289
test_mode: testMode
290+
}, {
291+
headers: { Authorization: `Bearer ${token}` }
281292
});
282293

283294
if (response.data.error) {

0 commit comments

Comments
 (0)