Skip to content

Commit 79ce397

Browse files
added auh token to frontend ai api
1 parent 6543480 commit 79ce397

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Frontend/src/App/CodeEditor/AIPanel.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ export default function AskAIPanel() {
3838
}, 100);
3939
};
4040

41+
const getToken = () => {
42+
const storageKey = `sb-${
43+
import.meta.env.VITE_SUPABASE_PROJECT_ID
44+
}-auth-token`;
45+
const sessionDataString = localStorage.getItem(storageKey);
46+
const sessionData = JSON.parse(sessionDataString || "null");
47+
return sessionData?.access_token || "";
48+
};
49+
4150
useEffect(() => {
4251
scrollToBottom();
4352
}, [messages, isLoading]); // Also scroll when loading state changes
@@ -56,6 +65,7 @@ export default function AskAIPanel() {
5665
method: "POST",
5766
headers: {
5867
"Content-Type": "application/json",
68+
Authorization: getToken(),
5969
},
6070
body: JSON.stringify({ messages: [...messages, userMessage] }),
6171
});

0 commit comments

Comments
 (0)