Skip to content

Commit f2f5fac

Browse files
committed
Refactor dashboard into AuthContext, types, useFetch, and useWebsocket hooks
1 parent ac20ff5 commit f2f5fac

10 files changed

Lines changed: 386 additions & 338 deletions

File tree

frontend/app/components/CreateCircleModal.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { useAuth } from '../context/authContext';
23

34
interface CreateCircleModalProps {
45
isOpen: boolean;
@@ -10,18 +11,24 @@ function CreateCircleModal({ isOpen, setOpen }: CreateCircleModalProps) {
1011
name: string;
1112
}
1213

13-
const createCircle = (circleName: string): void => {
14+
const authContext = useAuth();
15+
if (!authContext) {
16+
throw new Error("useAuth must be used within an AuthProvider");
17+
}
18+
const { getAccessToken } = authContext;
19+
20+
async function createCircle(circleName: string): Promise<void> {
1421
if (circleName === '') return;
1522
const data: CircleData = {
1623
name: circleName
1724
};
25+
const token = await getAccessToken();
1826
fetch('https://127.0.0.1:8000/api/circles', {
1927
method: 'POST',
2028
headers: {
21-
'Content-Type': 'application/json',
29+
'Authorization': `Bearer ${token}`,
2230
},
2331
body: JSON.stringify(data),
24-
credentials: 'include',
2532
});
2633
};
2734

0 commit comments

Comments
 (0)