Skip to content

Commit

Permalink
fix: redirect users to login for authenticated actions
Browse files Browse the repository at this point in the history
  • Loading branch information
sunaurus committed Mar 30, 2024
1 parent 9d7c58f commit 0fe22e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
10 changes: 0 additions & 10 deletions src/app/communities/SubscribeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ export const SubscribeButton = (props: {
readonly communityId: number;
readonly communityName: string;
}) => {
const { pending } = useFormStatus();

if (!props.loggedInUser) {
return null;
}

if (pending) {
return <Spinner />;
}

switch (props.currentStatus) {
case "Subscribed":
return (
Expand Down
9 changes: 9 additions & 0 deletions src/app/create_post/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ import { apiClient } from "@/app/apiClient";
import { formatCommunityName } from "@/app/c/formatCommunityName";
import { PageWithSidebar } from "@/app/PageWithSidebar";
import { PostEditor } from "@/app/create_post/PostEditor";
import { loginPageWithRedirectAction } from "@/app/login/authActions";

const CreatePostPage = async (props: {
readonly searchParams: { community_id?: number };
}) => {
const { my_user: loggedInUser } = await apiClient.getSite();
if (!loggedInUser) {
await loginPageWithRedirectAction(
`/create_post?community_id=${props.searchParams.community_id}`,
true,
);
}

const { community_view: communityView, moderators: mods } =
await apiClient.getCommunity({
id: props.searchParams.community_id,
Expand Down
6 changes: 6 additions & 0 deletions src/app/post/[id]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import { apiClient } from "@/app/apiClient";
import { formatCommunityName } from "@/app/c/formatCommunityName";
import { PageWithSidebar } from "@/app/PageWithSidebar";
import { PostEditor } from "@/app/create_post/PostEditor";
import { loginPageWithRedirectAction } from "@/app/login/authActions";

const EditPostPage = async (props: { readonly params: { id: number } }) => {
const { my_user: loggedInUser } = await apiClient.getSite();
if (!loggedInUser) {
await loginPageWithRedirectAction(`/post/${props.params.id}/edit`, true);
}

const {
post_view: postView,
community_view: communityView,
Expand Down

0 comments on commit 0fe22e5

Please sign in to comment.