Skip to content

Commit e6bbb57

Browse files
committed
feat: 워크스페이스에 권한이 없을 시, /으로 redirect
1 parent 3d8fd9c commit e6bbb57

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

apps/frontend/src/app/App.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@ import { CanvasView } from "@/widgets/CanvasView";
44
import { EditorView } from "@/widgets/EditorView";
55
import { PageSideBarView } from "@/widgets/PageSideBarView";
66
import { CanvasToolsView } from "@/widgets/CanvasToolsView";
7-
import { useGetUser } from "@/features/auth/model/useAuth";
7+
import { useProtectedWorkspace } from "@/features/workspace/model/useProtectedWorkspace";
88

99
function App() {
1010
useSyncedUsers();
11-
useGetUser();
11+
const { isLoading } = useProtectedWorkspace();
1212

13+
if (isLoading) {
14+
return (
15+
<div className="fixed inset-0 flex items-center justify-center bg-white">
16+
<div className="animate-pulse text-gray-400">Loading...</div>
17+
</div>
18+
);
19+
}
20+
21+
// If we're not loading and have workspace data, show the main content
1322
return (
1423
<div className="fixed inset-0 bg-white">
1524
<SideWrapper side="right" className="z-50">
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { useEffect } from "react";
2+
import { useNavigate } from "@tanstack/react-router";
3+
import { useCurrentWorkspace } from "@/features/workspace/model/useWorkspace";
4+
5+
export const useProtectedWorkspace = () => {
6+
const navigate = useNavigate();
7+
const { data: workspaceData, isLoading } = useCurrentWorkspace();
8+
9+
useEffect(() => {
10+
if (!isLoading && !workspaceData) {
11+
navigate({ to: "/" });
12+
}
13+
}, [isLoading, workspaceData, navigate]);
14+
15+
return {
16+
isLoading,
17+
workspaceData,
18+
};
19+
};

apps/frontend/src/features/workspace/model/useWorkspace.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,15 @@ export const useRemoveWorkspace = () => {
4242

4343
export const useCurrentWorkspace = () => {
4444
const workspaceId = useWorkspace();
45-
const { data: user, isError } = useGetUser();
45+
const { data: user, isError, isSuccess } = useGetUser();
46+
47+
const snowflakeId = isError ? "null" : (user?.snowflakeId ?? "null");
4648

4749
return useQuery({
48-
queryKey: [
49-
"currentWorkspace",
50-
workspaceId,
51-
isError ? "null" : (user?.snowflakeId ?? "null"),
52-
],
53-
queryFn: () =>
54-
getCurrentWorkspace(
55-
workspaceId,
56-
isError ? "null" : (user?.snowflakeId ?? "null"),
57-
),
58-
enabled: Boolean(workspaceId),
50+
queryKey: ["currentWorkspace", workspaceId, snowflakeId],
51+
queryFn: () => getCurrentWorkspace(workspaceId, snowflakeId),
52+
enabled: Boolean(workspaceId) && isSuccess,
53+
retry: false,
54+
refetchOnWindowFocus: false,
5955
});
6056
};

0 commit comments

Comments
 (0)