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: private link for a team event gives 404 #14473

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 46 additions & 22 deletions apps/web/lib/d/[link]/[slug]/getServerSideProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,62 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
team: {
select: {
id: true,
slug: true,
hideBranding: true,
},
},
},
},
},
});

const username = hashedLink?.eventType.users[0]?.username;
let name: string;
let isAway = false;
let hideBranding = false;

const notFound = {
notFound: true,
} as const;

if (!hashedLink || !username) {
if (!hashedLink) {
return notFound;
}

if (!org) {
const redirect = await getTemporaryOrgRedirect({
slugs: [username],
redirectType: RedirectType.User,
eventTypeSlug: slug,
currentQuery: context.query,
});
if (hashedLink.eventType.team) {
name = hashedLink.eventType.team.slug || "";
hideBranding = hashedLink.eventType.team.hideBranding;
} else {
const username = hashedLink.eventType.users[0]?.username;

if (redirect) {
return redirect;
if (!username) {
return notFound;
}
}

const [user] = await UserRepository.findUsersByUsername({
usernameList: [username],
orgSlug: org,
});
if (!org) {
const redirect = await getTemporaryOrgRedirect({
slugs: [username],
redirectType: RedirectType.User,
eventTypeSlug: slug,
currentQuery: context.query,
});

if (redirect) {
return redirect;
}
}

if (!user) {
return notFound;
const [user] = await UserRepository.findUsersByUsername({
usernameList: [username],
orgSlug: org,
});

if (!user) {
return notFound;
}

name = username;
isAway = user.away;
hideBranding = user.hideBranding;
}

let booking: GetBookingType | null = null;
Expand All @@ -90,7 +109,12 @@ async function getUserPageProps(context: GetServerSidePropsContext) {

// We use this to both prefetch the query on the server,
// as well as to check if the event exist, so we c an show a 404 otherwise.
const eventData = await ssr.viewer.public.event.fetch({ username, eventSlug: slug, isTeamEvent, org });
const eventData = await ssr.viewer.public.event.fetch({
username: name,
eventSlug: slug,
isTeamEvent,
org,
});

if (!eventData) {
return notFound;
Expand All @@ -105,11 +129,11 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
eventData.length
),
booking,
away: user?.away,
user: username,
away: isAway,
user: name,
slug,
trpcState: ssr.dehydrate(),
isBrandingHidden: user?.hideBranding,
isBrandingHidden: hideBranding,
// Sending the team event from the server, because this template file
// is reused for both team and user events.
isTeamEvent,
Expand Down