Skip to content

Commit

Permalink
feat: socketStore에 accessToken의존성 부여
Browse files Browse the repository at this point in the history
- socket 생성때 auth에서 사용한 accessToken을 활용
- null 일경우 guestWorkspace를 표현할 예정

#181
  • Loading branch information
hyonun321 committed Nov 24, 2024
1 parent dae1b3a commit 70311db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const App = () => {

useEffect(() => {
const socketStore = useSocketStore.getState();
socketStore.init();
socketStore.init(accessToken);
return () => {
setTimeout(() => {
socketStore.cleanup();
}, 0);
};
}, []);
}, [accessToken]);

return (
<>
Expand Down
8 changes: 5 additions & 3 deletions client/src/stores/useSocketStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface SocketStore {
socket: Socket | null;
clientId: number | null;
workspace: WorkSpaceSerializedProps | null;
init: () => void;
init: (accessToken: string | null) => void;
cleanup: () => void;
fetchWorkspaceData: () => WorkSpaceSerializedProps | null;
sendPageCreateOperation: (operation: RemotePageCreateOperation) => void;
Expand Down Expand Up @@ -51,9 +51,8 @@ export const useSocketStore = create<SocketStore>((set, get) => ({
clientId: null,
workspace: null,

init: () => {
init: (accessToken: string | null) => {
const { socket: existingSocket } = get();
if (existingSocket?.connected) return;

if (existingSocket) {
existingSocket.disconnect();
Expand All @@ -68,6 +67,9 @@ export const useSocketStore = create<SocketStore>((set, get) => ({
withCredentials: true,
reconnectionAttempts: 5,
reconnectionDelay: 1000,
auth: {
token: accessToken,
},
autoConnect: false,
});

Expand Down

0 comments on commit 70311db

Please sign in to comment.