Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 500 on forbidden showing up in logs #14636

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,26 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
} as const;
return redirect;
}

await ssr.viewer.eventTypes.get.prefetch({ id: typeParam });

const { eventType } = await ssr.viewer.eventTypes.get.fetch({ id: typeParam });

const getEventTypeById = async (eventTypeId: number) => {
await ssr.viewer.eventTypes.get.prefetch({ id: eventTypeId });
try {
const { eventType } = await ssr.viewer.eventTypes.get.fetch({ id: eventTypeId });
return eventType;
} catch (e: unknown) {
// reject, user has no access to this event type.
return null;
}
};
const eventType = await getEventTypeById(typeParam);
if (!eventType) {
const redirect = {
redirect: {
permanent: false,
destination: "/event-types",
},
} as const;
return redirect;
}
return {
props: {
eventType,
Expand Down
3 changes: 1 addition & 2 deletions packages/trpc/server/routers/viewer/eventTypes/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ export const eventOwnerProcedure = authedProcedure
})();

if (!isAuthorized) {
console.warn(`User ${ctx.user.id} attempted to an access an event ${event.id} they do not own.`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this information - also FORBIDDEN is the right code to throw here.

throw new TRPCError({ code: "UNAUTHORIZED" });
throw new TRPCError({ code: "FORBIDDEN" });
}

const isAllowed = (function () {
Expand Down
Loading