2023-02-08 21:51:58 +00:00
|
|
|
import { get } from "@vercel/edge-config";
|
2022-06-02 16:19:01 +00:00
|
|
|
import { collectEvents } from "next-collect/server";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { NextMiddleware } from "next/server";
|
|
|
|
import { NextResponse, userAgent } from "next/server";
|
2022-06-02 16:19:01 +00:00
|
|
|
|
2022-08-16 19:55:50 +00:00
|
|
|
import { CONSOLE_URL, WEBAPP_URL, WEBSITE_URL } from "@calcom/lib/constants";
|
2022-08-23 21:34:10 +00:00
|
|
|
import { isIpInBanlist } from "@calcom/lib/getIP";
|
2022-07-28 19:58:26 +00:00
|
|
|
import { extendEventData, nextCollectBasicSettings } from "@calcom/lib/telemetry";
|
2022-06-02 16:19:01 +00:00
|
|
|
|
2022-08-09 09:21:15 +00:00
|
|
|
const middleware: NextMiddleware = async (req) => {
|
|
|
|
const url = req.nextUrl;
|
2023-04-21 15:08:59 +00:00
|
|
|
const requestHeaders = new Headers(req.headers);
|
2023-06-15 16:36:25 +00:00
|
|
|
/**
|
|
|
|
* We are using env variable to toggle new-booker because using flags would be an unnecessary delay for booking pages
|
|
|
|
* Also, we can't easily identify the booker page requests here(to just fetch the flags for those requests)
|
|
|
|
*/
|
feat: Organizations (#8993)
* Initial commit
* Adding feature flag
* feat: Orgs Schema Changing `scopedMembers` to `orgUsers` (#9209)
* Change scopedMembers to orgMembers
* Change to orgUsers
* Letting duplicate slugs for teams to support orgs
* Covering null on unique clauses
* Supporting having the orgId in the session cookie
* feat: organization event type filter (#9253)
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Missing changes to support orgs schema changes
* feat: Onboarding process to create an organization (#9184)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Making sure we check requestedSlug now
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* feat: [CAL-1816] Organization subdomain support (#9345)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* Covering users and subteams, excluding non-org users
* Unpublished teams shows correctly
* Create subdomain in Vercel
* feedback
* Renaming Vercel env vars
* Vercel domain check before creation
* Supporting cal-staging.com
* Change to have vercel detect it
* vercel domain check data message error
* Remove check domain
* Making sure we check requestedSlug now
* Feedback and unneeded code
* Reverting unneeded changes
* Unneeded changes
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Vercel subdomain creation in PROD only
* Making sure we let localhost still work
* Feedback
* Type check fixes
* feat: Organization branding in side menu (#9279)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Org branding provider used in shell sidebar
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Using org avatar (temp)
* Not showing org logo if not set
* User onboarding with org branding (slug)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Feedback
* Org public profile
* Public profiles for team event types
* Added setup profile alert
* Using org avatar on subteams avatar
* Making sure we show the set up profile on org only
* Profile username availability rely on org hook
* Update apps/web/pages/team/[slug].tsx
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Update apps/web/pages/team/[slug].tsx
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* feat: Organization support for event types page (#9449)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Org branding provider used in shell sidebar
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Using org avatar (temp)
* Not showing org logo if not set
* User onboarding with org branding (slug)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Feedback
* Org public profile
* Public profiles for team event types
* Added setup profile alert
* Using org avatar on subteams avatar
* Processing orgs and children as profile options
* Reverting change not belonging to this PR
* Making sure we show the set up profile on org only
* Removing console.log
* Comparing memberships to choose the highest one
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Type errors
* Refactor and type fixes
* Update orgDomains.ts
* Feedback
* Reverting
* NIT
* fix issue getting org slug from domain
* Improving orgDomains util
* Host comes with port
* Update useRouterQuery.ts
* Feedback
* Feedback
* Feedback
* Feedback: SSR for user event-types to have org context
* chore: Cache node_modules (#9492)
* Adding check for cache hit
* Adding a separate install step first
* Put the restore cache steps back
* Revert the uses type for restoring cache
* Added step to restore nm cache
* Removed the cache-hit check
* Comments and naming
* Removed extra install command
* Updated the name of the linting step to be more clear
* Removes the need for useEffect here
* Feedback
* Feedback
* Cookie domain needs a dot
* Type fix
* Update apps/web/public/static/locales/en/common.json
Co-authored-by: Omar López <zomars@me.com>
* Update packages/emails/src/templates/OrganizationAccountVerifyEmail.tsx
* Feedback
---------
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Efraín Rochín <roae.85@gmail.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
2023-06-14 21:40:20 +00:00
|
|
|
|
2023-06-14 14:38:34 +00:00
|
|
|
if (isIpInBanlist(req) && url.pathname !== "/api/nope") {
|
|
|
|
// DDOS Prevention: Immediately end request with no response - Avoids a redirect as well initiated by NextAuth on invalid callback
|
|
|
|
req.nextUrl.pathname = "/api/nope";
|
|
|
|
return NextResponse.redirect(req.nextUrl);
|
|
|
|
}
|
|
|
|
|
2023-02-08 21:51:58 +00:00
|
|
|
if (!url.pathname.startsWith("/api")) {
|
|
|
|
//
|
|
|
|
// NOTE: When tRPC hits an error a 500 is returned, when this is received
|
|
|
|
// by the application the user is automatically redirected to /auth/login.
|
|
|
|
//
|
|
|
|
// - For this reason our matchers are sufficient for an app-wide maintenance page.
|
|
|
|
//
|
|
|
|
try {
|
|
|
|
// Check whether the maintenance page should be shown
|
|
|
|
const isInMaintenanceMode = await get<boolean>("isInMaintenanceMode");
|
|
|
|
// If is in maintenance mode, point the url pathname to the maintenance page
|
|
|
|
if (isInMaintenanceMode) {
|
|
|
|
req.nextUrl.pathname = `/maintenance`;
|
|
|
|
return NextResponse.rewrite(req.nextUrl);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
// show the default page if EDGE_CONFIG env var is missing,
|
|
|
|
// but log the error to the console
|
|
|
|
// console.error(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-23 21:34:10 +00:00
|
|
|
if (["/api/collect-events", "/api/auth"].some((p) => url.pathname.startsWith(p))) {
|
2022-08-16 17:15:13 +00:00
|
|
|
const callbackUrl = url.searchParams.get("callbackUrl");
|
2022-08-16 19:50:09 +00:00
|
|
|
const { isBot } = userAgent(req);
|
2022-08-16 19:55:50 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
isBot ||
|
2022-08-23 21:34:10 +00:00
|
|
|
(callbackUrl && ![CONSOLE_URL, WEBAPP_URL, WEBSITE_URL].some((u) => callbackUrl.startsWith(u))) ||
|
|
|
|
isIpInBanlist(req)
|
2022-08-16 19:55:50 +00:00
|
|
|
) {
|
2022-08-16 17:15:13 +00:00
|
|
|
// DDOS Prevention: Immediately end request with no response - Avoids a redirect as well initiated by NextAuth on invalid callback
|
2022-08-16 19:59:38 +00:00
|
|
|
req.nextUrl.pathname = "/api/nope";
|
|
|
|
return NextResponse.redirect(req.nextUrl);
|
2022-08-16 17:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-22 17:23:43 +00:00
|
|
|
|
|
|
|
// Don't 404 old routing_forms links
|
|
|
|
if (url.pathname.startsWith("/apps/routing_forms")) {
|
|
|
|
url.pathname = url.pathname.replace("/apps/routing_forms", "/apps/routing-forms");
|
|
|
|
return NextResponse.rewrite(url);
|
|
|
|
}
|
|
|
|
|
2023-02-09 01:12:45 +00:00
|
|
|
if (url.pathname.startsWith("/api/trpc/")) {
|
|
|
|
requestHeaders.set("x-cal-timezone", req.headers.get("x-vercel-ip-timezone") ?? "");
|
|
|
|
}
|
|
|
|
|
2023-02-06 22:50:08 +00:00
|
|
|
if (url.pathname.startsWith("/auth/login")) {
|
|
|
|
// Use this header to actually enforce CSP, otherwise it is running in Report Only mode on all pages.
|
2023-04-21 15:08:59 +00:00
|
|
|
requestHeaders.set("x-csp-enforce", "true");
|
2023-02-06 22:50:08 +00:00
|
|
|
}
|
|
|
|
|
2023-04-21 15:08:59 +00:00
|
|
|
return NextResponse.next({
|
|
|
|
request: {
|
|
|
|
headers: requestHeaders,
|
|
|
|
},
|
|
|
|
});
|
2022-08-09 09:21:15 +00:00
|
|
|
};
|
|
|
|
|
2022-11-03 14:51:43 +00:00
|
|
|
export const config = {
|
2023-02-06 22:50:08 +00:00
|
|
|
matcher: [
|
2023-06-14 14:38:34 +00:00
|
|
|
"/:path*",
|
2023-02-06 22:50:08 +00:00
|
|
|
"/api/collect-events/:path*",
|
|
|
|
"/api/auth/:path*",
|
|
|
|
"/apps/routing_forms/:path*",
|
|
|
|
"/:path*/embed",
|
2023-02-09 01:12:45 +00:00
|
|
|
"/api/trpc/:path*",
|
2023-02-06 22:50:08 +00:00
|
|
|
"/auth/login",
|
|
|
|
],
|
2022-11-03 14:51:43 +00:00
|
|
|
};
|
|
|
|
|
2022-06-02 16:19:01 +00:00
|
|
|
export default collectEvents({
|
2022-08-09 09:21:15 +00:00
|
|
|
middleware,
|
2022-06-02 16:19:01 +00:00
|
|
|
...nextCollectBasicSettings,
|
|
|
|
cookieName: "__clnds",
|
|
|
|
extend: extendEventData,
|
|
|
|
});
|