Skip to content

Commit d5de7c6

Browse files
committed
fix: 코드리뷰 반영
1 parent 1a9ebf4 commit d5de7c6

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/components/ui/sidebar.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export function Sidebar({
3030
isLoggedIn,
3131
isCheckingAuth,
3232
hasFetchedAuth,
33+
lastCheckedShareUri,
3334
checkAuth,
3435
checkAuthForSharedBoard,
3536
reset: resetAuth,
@@ -45,12 +46,14 @@ export function Sidebar({
4546
const isSharedBoard = Boolean(shareUri);
4647

4748
useEffect(() => {
48-
if (hasFetchedAuth || isCheckingAuth) return;
49+
if (isCheckingAuth) return;
4950

5051
if (isSharedBoard && shareUri) {
5152
// 공유 보드
52-
void checkAuthForSharedBoard(shareUri);
53-
} else {
53+
if (lastCheckedShareUri !== shareUri) {
54+
void checkAuthForSharedBoard(shareUri);
55+
}
56+
} else if (!hasFetchedAuth) {
5457
// 내 보드
5558
void checkAuth();
5659
}
@@ -60,6 +63,7 @@ export function Sidebar({
6063
checkAuth,
6164
checkAuthForSharedBoard,
6265
hasFetchedAuth,
66+
lastCheckedShareUri,
6367
isCheckingAuth,
6468
]);
6569

src/stores/useAuthStore.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ interface AuthState {
77
isLoggedIn: boolean;
88
isCheckingAuth: boolean;
99
hasFetchedAuth: boolean;
10+
lastCheckedShareUri: string | null;
1011
boardShare: GetBoardShareResponse["data"] | null;
1112
checkAuth: (options?: {
1213
force?: boolean;
1314
}) => Promise<GetBoardShareResponse["data"] | null>;
1415
checkAuthForSharedBoard: (
15-
shareUri: string
16+
shareUri: string,
17+
options?: { force?: boolean }
1618
) => Promise<CheckLoginResponse["data"] | null>;
1719
setLoggedIn: (
1820
value: boolean,
@@ -25,6 +27,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
2527
isLoggedIn: false,
2628
isCheckingAuth: false,
2729
hasFetchedAuth: false,
30+
lastCheckedShareUri: null,
2831
boardShare: null,
2932

3033
checkAuth: async ({ force = false } = {}) => {
@@ -59,10 +62,11 @@ export const useAuthStore = create<AuthState>((set, get) => ({
5962
}
6063
},
6164

62-
checkAuthForSharedBoard: async (shareUri: string) => {
63-
const { hasFetchedAuth } = get();
65+
checkAuthForSharedBoard: async (shareUri: string, { force = false } = {}) => {
66+
const { lastCheckedShareUri } = get();
6467

65-
if (hasFetchedAuth) {
68+
// 같은 shareUri로 이미 체크했으면 스킵 (force가 아닌 경우)
69+
if (lastCheckedShareUri === shareUri && !force) {
6670
return null;
6771
}
6872

@@ -75,6 +79,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
7579
isLoggedIn: response.data.validUser,
7680
isCheckingAuth: false,
7781
hasFetchedAuth: true,
82+
lastCheckedShareUri: shareUri,
7883
});
7984

8085
return response.data;
@@ -83,6 +88,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
8388
isLoggedIn: false,
8489
isCheckingAuth: false,
8590
hasFetchedAuth: true,
91+
lastCheckedShareUri: shareUri,
8692
});
8793

8894
return null;
@@ -103,6 +109,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
103109
isLoggedIn: false,
104110
isCheckingAuth: false,
105111
hasFetchedAuth: true,
112+
lastCheckedShareUri: null,
106113
boardShare: null,
107114
});
108115
},

0 commit comments

Comments
 (0)