Skip to content

Commit

Permalink
fix: 500 on forbidden showing up in logs (#14636)
Browse files Browse the repository at this point in the history
  • Loading branch information
emrysal committed Apr 17, 2024
1 parent b9ac22d commit 0f8a0ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
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.`);
throw new TRPCError({ code: "UNAUTHORIZED" });
throw new TRPCError({ code: "FORBIDDEN" });
}

const isAllowed = (function () {
Expand Down

0 comments on commit 0f8a0ea

Please sign in to comment.