Skip to content

Commit f7cb62e

Browse files
committed
fix: show not found if not own post
1 parent dca2ca6 commit f7cb62e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/containers/write/ActiveEditor.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
} from '../../lib/graphql/post';
2121
import { safe } from '../../lib/utils';
2222
import PopupOKCancel from '../../components/common/PopupOKCancel';
23+
import { useUserId } from '../../lib/hooks/useUser';
24+
import NotFoundPage from '../../pages/NotFoundPage';
2325

2426
export type ActiveEditorProps = {};
2527

@@ -29,6 +31,7 @@ const ActiveEditor: React.FC<ActiveEditorProps> = () => {
2931
const postId = useSelector((state: RootState) => state.write.postId);
3032
const [askLoadTemp, setAskLoadTemp] = useState(false);
3133
const initialized = useRef(false);
34+
const userId = useUserId();
3235

3336
const dispatch = useDispatch();
3437
const location = useLocation();
@@ -128,6 +131,13 @@ const ActiveEditor: React.FC<ActiveEditorProps> = () => {
128131
// dispatch(setInitialBody(lastPostHistory.body));
129132
}, [dispatch, lastPostHistory, post]);
130133

134+
if (
135+
(!readPostForEdit.loading && post === null) ||
136+
(post && post.user.id !== userId)
137+
) {
138+
return <NotFoundPage />;
139+
}
140+
131141
if (id && !post && !postId) return null;
132142

133143
return (

src/lib/graphql/post.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ export const READ_POST_FOR_EDIT = gql`
341341
id
342342
name
343343
}
344+
user {
345+
id
346+
}
344347
}
345348
}
346349
`;
@@ -396,6 +399,9 @@ export type ReadPostForEditResponse = {
396399
name: string;
397400
} | null;
398401
updated_at: string;
402+
user: {
403+
id: string;
404+
};
399405
};
400406
};
401407

0 commit comments

Comments
 (0)