From 744c8ac7b3bdc573cc261f7d908b50da737abcaf Mon Sep 17 00:00:00 2001 From: Flavien David Date: Tue, 5 Mar 2024 11:28:19 +0100 Subject: [PATCH] Wrap SSR with auth requirements (#4129) * Add `withGetServerSidePropsRequirements` wrapper * :shirt: * :sparkles: * :scissors: * :shirt: * Address comments from review --- front/lib/auth.ts | 2 +- front/lib/iam/session.ts | 51 +++++++ front/pages/index.tsx | 41 +++--- front/pages/login-error.tsx | 27 ++-- front/pages/no-workspace.tsx | 4 +- .../poke/[wId]/assistants/[aId]/index.tsx | 4 +- .../poke/[wId]/data_sources/[name]/index.tsx | 4 +- .../poke/[wId]/data_sources/[name]/search.tsx | 4 +- .../poke/[wId]/data_sources/[name]/view.tsx | 4 +- front/pages/poke/[wId]/index.tsx | 4 +- front/pages/poke/[wId]/memberships.tsx | 4 +- .../poke/connectors/[connectorId]/index.tsx | 4 +- front/pages/poke/index.tsx | 4 +- front/pages/poke/plans.tsx | 4 +- front/pages/w/[wId]/a/[aId]/clone.tsx | 4 +- .../w/[wId]/a/[aId]/datasets/[name]/index.tsx | 4 +- .../pages/w/[wId]/a/[aId]/datasets/index.tsx | 4 +- front/pages/w/[wId]/a/[aId]/datasets/new.tsx | 4 +- front/pages/w/[wId]/a/[aId]/execute/index.tsx | 4 +- front/pages/w/[wId]/a/[aId]/index.tsx | 4 +- .../w/[wId]/a/[aId]/runs/[runId]/index.tsx | 4 +- front/pages/w/[wId]/a/[aId]/runs/index.tsx | 4 +- front/pages/w/[wId]/a/[aId]/settings.tsx | 4 +- front/pages/w/[wId]/a/[aId]/specification.tsx | 4 +- front/pages/w/[wId]/a/index.tsx | 4 +- front/pages/w/[wId]/a/new.tsx | 4 +- front/pages/w/[wId]/assistant/[cId]/index.tsx | 4 +- front/pages/w/[wId]/assistant/assistants.tsx | 4 +- front/pages/w/[wId]/assistant/gallery.tsx | 4 +- front/pages/w/[wId]/assistant/new.tsx | 4 +- .../[wId]/builder/assistants/[aId]/index.tsx | 4 +- .../pages/w/[wId]/builder/assistants/dust.tsx | 4 +- .../w/[wId]/builder/assistants/index.tsx | 4 +- .../pages/w/[wId]/builder/assistants/new.tsx | 4 +- .../data-sources/[name]/edit-public-url.tsx | 4 +- .../builder/data-sources/[name]/index.tsx | 4 +- .../builder/data-sources/[name]/search.tsx | 4 +- .../builder/data-sources/[name]/settings.tsx | 4 +- .../data-sources/[name]/tables/upsert.tsx | 4 +- .../builder/data-sources/[name]/upsert.tsx | 4 +- .../w/[wId]/builder/data-sources/managed.tsx | 4 +- .../builder/data-sources/new-public-url.tsx | 4 +- .../w/[wId]/builder/data-sources/new.tsx | 4 +- .../builder/data-sources/public-urls.tsx | 4 +- .../w/[wId]/builder/data-sources/static.tsx | 4 +- front/pages/w/[wId]/index.tsx | 4 +- front/pages/w/[wId]/join.tsx | 126 ++++++++++-------- front/pages/w/[wId]/members/index.tsx | 4 +- front/pages/w/[wId]/subscription/index.tsx | 4 +- .../upgrade-enterprise/[secret].tsx | 4 +- .../w/[wId]/u/extract/events/[sId]/edit.tsx | 4 +- front/pages/w/[wId]/u/extract/index.tsx | 4 +- .../[wId]/u/extract/templates/[sId]/edit.tsx | 4 +- .../[wId]/u/extract/templates/[sId]/index.tsx | 4 +- .../pages/w/[wId]/u/extract/templates/new.tsx | 4 +- front/pages/w/[wId]/welcome.tsx | 4 +- front/pages/w/[wId]/workspace/index.tsx | 4 +- 57 files changed, 262 insertions(+), 193 deletions(-) diff --git a/front/lib/auth.ts b/front/lib/auth.ts index 0d860e1e37b8..672aa8e86497 100644 --- a/front/lib/auth.ts +++ b/front/lib/auth.ts @@ -446,7 +446,7 @@ export class Authenticator { export async function getSession( req: NextApiRequest | GetServerSidePropsContext["req"], res: NextApiResponse | GetServerSidePropsContext["res"] -): Promise { +): Promise { return getServerSession(req, res, authOptions); } diff --git a/front/lib/iam/session.ts b/front/lib/iam/session.ts index c5c3cc0b790c..54d65c34ea3f 100644 --- a/front/lib/iam/session.ts +++ b/front/lib/iam/session.ts @@ -1,11 +1,19 @@ import type { RoleType, UserTypeWithWorkspaces } from "@dust-tt/types"; +import type { + GetServerSideProps, + GetServerSidePropsContext, + PreviewData, +} from "next"; +import type { ParsedUrlQuery } from "querystring"; import { Op } from "sequelize"; +import { getSession } from "@app/lib/auth"; import { fetchUserFromSession, maybeUpdateFromExternalUser, } from "@app/lib/iam/users"; import { Membership, Workspace } from "@app/lib/models"; +import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; export function isGoogleSession(session: any) { return session.provider.provider === "google"; @@ -75,3 +83,46 @@ export async function getUserFromSession( }), }; } + +interface WithGetServerSidePropsRequirementsOptions { + enableLogging?: boolean; + requireAuth?: boolean; +} + +const defaultWithGetServerSidePropsRequirements: WithGetServerSidePropsRequirementsOptions = + { + enableLogging: true, + requireAuth: true, + }; + +export function withGetServerSidePropsRequirements< + T extends { [key: string]: any } = { [key: string]: any } +>( + getServerSideProps: GetServerSideProps, + opts: WithGetServerSidePropsRequirementsOptions = defaultWithGetServerSidePropsRequirements +): GetServerSideProps { + return async ( + context: GetServerSidePropsContext + ) => { + const { enableLogging, requireAuth } = opts; + + if (requireAuth) { + const session = await getSession(context.req, context.res); + if (!session) { + return { + redirect: { + permanent: false, + // TODO(2024-03-04 flav) Add support for `returnTo=`. + destination: "/", + }, + }; + } + } + + if (enableLogging) { + return withGetServerSidePropsLogging(getServerSideProps)(context); + } + + return getServerSideProps(context); + }; +} diff --git a/front/pages/index.tsx b/front/pages/index.tsx index 85670d82d58e..8526e10d8030 100644 --- a/front/pages/index.tsx +++ b/front/pages/index.tsx @@ -52,36 +52,41 @@ import ScrollingHeader from "@app/components/home/scrollingHeader"; import { PricePlans } from "@app/components/PlansTables"; import { getSession } from "@app/lib/auth"; import { getUserFromSession } from "@app/lib/iam/session"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ gaTrackingId: string; -}>(async (context) => { - const session = await getSession(context.req, context.res); - const user = await getUserFromSession(session); +}>( + async (context) => { + const session = await getSession(context.req, context.res); + const user = await getUserFromSession(session); - if (user && user.workspaces.length > 0) { - let url = `/w/${user.workspaces[0].sId}`; + if (user && user.workspaces.length > 0) { + let url = `/w/${user.workspaces[0].sId}`; - if (context.query.inviteToken) { - url = `/api/login?inviteToken=${context.query.inviteToken}`; + if (context.query.inviteToken) { + url = `/api/login?inviteToken=${context.query.inviteToken}`; + } + + return { + redirect: { + destination: url, + permanent: false, + }, + }; } return { - redirect: { - destination: url, - permanent: false, - }, + props: { gaTrackingId: GA_TRACKING_ID }, }; + }, + { + requireAuth: false, } - - return { - props: { gaTrackingId: GA_TRACKING_ID }, - }; -}); +); export default function Home({ gaTrackingId, diff --git a/front/pages/login-error.tsx b/front/pages/login-error.tsx index 17a25b3e9f98..d6e39fb5471d 100644 --- a/front/pages/login-error.tsx +++ b/front/pages/login-error.tsx @@ -2,23 +2,28 @@ import { Button, Logo } from "@dust-tt/sparkle"; import type { InferGetServerSidePropsType } from "next"; import Link from "next/link"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; const { URL = "", GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ domain?: string; gaTrackingId: string; baseUrl: string; -}>(async (context) => { - return { - props: { - domain: context.query.domain as string, - baseUrl: URL, - gaTrackingId: GA_TRACKING_ID, - }, - }; -}); +}>( + async (context) => { + return { + props: { + domain: context.query.domain as string, + baseUrl: URL, + gaTrackingId: GA_TRACKING_ID, + }, + }; + }, + { + requireAuth: false, + } +); export default function LoginError({ domain, diff --git a/front/pages/no-workspace.tsx b/front/pages/no-workspace.tsx index c7f537bc064e..c18d3306ebc2 100644 --- a/front/pages/no-workspace.tsx +++ b/front/pages/no-workspace.tsx @@ -11,9 +11,9 @@ import { useRouter } from "next/router"; import { getSession } from "@app/lib/auth"; import { getUserFromSession } from "@app/lib/iam/session"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { Membership, Workspace, WorkspaceHasDomain } from "@app/lib/models"; import logger from "@app/logger/logger"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; // Fetch workspace details for scenarios where auto-join is disabled. async function fetchWorkspaceDetails( @@ -55,7 +55,7 @@ async function fetchRevokedWorkspace( return Workspace.findByPk(revokedWorkspaceId); } -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ status: "auto-join-disabled" | "revoked"; userFirstName: string; workspaceName: string; diff --git a/front/pages/poke/[wId]/assistants/[aId]/index.tsx b/front/pages/poke/[wId]/assistants/[aId]/index.tsx index 1ecd84e1455f..6bc8a2b56358 100644 --- a/front/pages/poke/[wId]/assistants/[aId]/index.tsx +++ b/front/pages/poke/[wId]/assistants/[aId]/index.tsx @@ -10,9 +10,9 @@ import type { InferGetServerSidePropsType } from "next"; import PokeNavbar from "@app/components/poke/PokeNavbar"; import { getAgentConfigurations } from "@app/lib/api/assistant/configuration"; import { Authenticator, getSession } from "@app/lib/auth"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ agentConfigurations: AgentConfigurationType[]; }>(async (context) => { const session = await getSession(context.req, context.res); diff --git a/front/pages/poke/[wId]/data_sources/[name]/index.tsx b/front/pages/poke/[wId]/data_sources/[name]/index.tsx index baf74d44d38c..9ea6ffe3a464 100644 --- a/front/pages/poke/[wId]/data_sources/[name]/index.tsx +++ b/front/pages/poke/[wId]/data_sources/[name]/index.tsx @@ -25,14 +25,14 @@ import { getDataSource } from "@app/lib/api/data_sources"; import { Authenticator, getSession } from "@app/lib/auth"; import { useSubmitFunction } from "@app/lib/client/utils"; import { getDisplayNameForDocument } from "@app/lib/data_sources"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { useDocuments } from "@app/lib/swr"; import { formatTimestampToFriendlyDate, timeAgoFrom } from "@app/lib/utils"; import logger from "@app/logger/logger"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { TEMPORAL_CONNECTORS_NAMESPACE = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; dataSource: DataSourceType; coreDataSource: CoreAPIDataSource; diff --git a/front/pages/poke/[wId]/data_sources/[name]/search.tsx b/front/pages/poke/[wId]/data_sources/[name]/search.tsx index cbf8f6a649f2..96cda8cabccd 100644 --- a/front/pages/poke/[wId]/data_sources/[name]/search.tsx +++ b/front/pages/poke/[wId]/data_sources/[name]/search.tsx @@ -10,10 +10,10 @@ import PokeNavbar from "@app/components/poke/PokeNavbar"; import { getDataSource } from "@app/lib/api/data_sources"; import { Authenticator, getSession } from "@app/lib/auth"; import { getDisplayNameForDocument } from "@app/lib/data_sources"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { classNames, timeAgoFrom } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; dataSource: DataSourceType; }>(async (context) => { diff --git a/front/pages/poke/[wId]/data_sources/[name]/view.tsx b/front/pages/poke/[wId]/data_sources/[name]/view.tsx index 1b4a9013d969..e1baa7494bea 100644 --- a/front/pages/poke/[wId]/data_sources/[name]/view.tsx +++ b/front/pages/poke/[wId]/data_sources/[name]/view.tsx @@ -6,11 +6,11 @@ import type { InferGetServerSidePropsType } from "next"; import PokeNavbar from "@app/components/poke/PokeNavbar"; import { getDataSource } from "@app/lib/api/data_sources"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; import logger from "@app/logger/logger"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ document: CoreAPIDocument; }>(async (context) => { const session = await getSession(context.req, context.res); diff --git a/front/pages/poke/[wId]/index.tsx b/front/pages/poke/[wId]/index.tsx index ce3b45d79257..7e7bf192c610 100644 --- a/front/pages/poke/[wId]/index.tsx +++ b/front/pages/poke/[wId]/index.tsx @@ -38,6 +38,7 @@ import { import { Authenticator, getSession } from "@app/lib/auth"; import { useSubmitFunction } from "@app/lib/client/utils"; import { isDevelopment } from "@app/lib/development"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { FREE_TEST_PLAN_CODE, FREE_UPGRADED_PLAN_CODE, @@ -45,9 +46,8 @@ import { } from "@app/lib/plans/plan_codes"; import { getPlanInvitation } from "@app/lib/plans/subscription"; import { usePokePlans } from "@app/lib/swr"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; planInvitation: PlanInvitationType | null; diff --git a/front/pages/poke/[wId]/memberships.tsx b/front/pages/poke/[wId]/memberships.tsx index cfb00b3a2395..c4c37d8f4969 100644 --- a/front/pages/poke/[wId]/memberships.tsx +++ b/front/pages/poke/[wId]/memberships.tsx @@ -11,9 +11,9 @@ import React from "react"; import PokeNavbar from "@app/components/poke/PokeNavbar"; import { getMembers } from "@app/lib/api/workspace"; import { Authenticator, getSession } from "@app/lib/auth"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; members: UserTypeWithWorkspaces[]; }>(async (context) => { diff --git a/front/pages/poke/connectors/[connectorId]/index.tsx b/front/pages/poke/connectors/[connectorId]/index.tsx index 4e68eaa7098e..452b542b94d8 100644 --- a/front/pages/poke/connectors/[connectorId]/index.tsx +++ b/front/pages/poke/connectors/[connectorId]/index.tsx @@ -2,10 +2,10 @@ import type { ConnectorType } from "@dust-tt/types"; import { ConnectorsAPI } from "@dust-tt/types"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import logger from "@app/logger/logger"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; -export const getServerSideProps = withGetServerSidePropsLogging( +export const getServerSideProps = withGetServerSidePropsRequirements( async (context) => { const session = await getSession(context.req, context.res); const auth = await Authenticator.fromSuperUserSession(session, null); diff --git a/front/pages/poke/index.tsx b/front/pages/poke/index.tsx index d658323009a1..bd33320af2e4 100644 --- a/front/pages/poke/index.tsx +++ b/front/pages/poke/index.tsx @@ -5,10 +5,10 @@ import React, { useState } from "react"; import PokeNavbar from "@app/components/poke/PokeNavbar"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { usePokeWorkspaces } from "@app/lib/swr"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; -export const getServerSideProps = withGetServerSidePropsLogging( +export const getServerSideProps = withGetServerSidePropsRequirements( async (context) => { const session = await getSession(context.req, context.res); const auth = await Authenticator.fromSuperUserSession(session, null); diff --git a/front/pages/poke/plans.tsx b/front/pages/poke/plans.tsx index 658401f19952..1b12a91874c1 100644 --- a/front/pages/poke/plans.tsx +++ b/front/pages/poke/plans.tsx @@ -23,10 +23,10 @@ import { import PokeNavbar from "@app/components/poke/PokeNavbar"; import { SendNotificationsContext } from "@app/components/sparkle/Notification"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { usePokePlans } from "@app/lib/swr"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; -export const getServerSideProps = withGetServerSidePropsLogging( +export const getServerSideProps = withGetServerSidePropsRequirements( async (context) => { const session = await getSession(context.req, context.res); const auth = await Authenticator.fromSuperUserSession(session, null); diff --git a/front/pages/w/[wId]/a/[aId]/clone.tsx b/front/pages/w/[wId]/a/[aId]/clone.tsx index 1d20ae42042f..a3999b950769 100644 --- a/front/pages/w/[wId]/a/[aId]/clone.tsx +++ b/front/pages/w/[wId]/a/[aId]/clone.tsx @@ -23,12 +23,12 @@ import WorkspacePicker from "@app/components/WorkspacePicker"; import { getApp } from "@app/lib/api/app"; import { Authenticator, getSession } from "@app/lib/auth"; import { getUserFromSession } from "@app/lib/iam/session"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ user: UserTypeWithWorkspaces; owner: WorkspaceType; subscription: SubscriptionType; diff --git a/front/pages/w/[wId]/a/[aId]/datasets/[name]/index.tsx b/front/pages/w/[wId]/a/[aId]/datasets/[name]/index.tsx index cd8d46af1061..bb90c46feed9 100644 --- a/front/pages/w/[wId]/a/[aId]/datasets/[name]/index.tsx +++ b/front/pages/w/[wId]/a/[aId]/datasets/[name]/index.tsx @@ -20,11 +20,11 @@ import { getApp } from "@app/lib/api/app"; import { getDatasetHash, getDatasetSchema } from "@app/lib/api/datasets"; import { Authenticator, getSession } from "@app/lib/auth"; import { useRegisterUnloadHandlers } from "@app/lib/front"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; diff --git a/front/pages/w/[wId]/a/[aId]/datasets/index.tsx b/front/pages/w/[wId]/a/[aId]/datasets/index.tsx index 3b7b27f7e191..8274a403214e 100644 --- a/front/pages/w/[wId]/a/[aId]/datasets/index.tsx +++ b/front/pages/w/[wId]/a/[aId]/datasets/index.tsx @@ -16,12 +16,12 @@ import { import { getApp } from "@app/lib/api/app"; import { getDatasets } from "@app/lib/api/datasets"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; diff --git a/front/pages/w/[wId]/a/[aId]/datasets/new.tsx b/front/pages/w/[wId]/a/[aId]/datasets/new.tsx index 09550da5d641..ba638b19ee53 100644 --- a/front/pages/w/[wId]/a/[aId]/datasets/new.tsx +++ b/front/pages/w/[wId]/a/[aId]/datasets/new.tsx @@ -20,11 +20,11 @@ import { getApp } from "@app/lib/api/app"; import { getDatasets } from "@app/lib/api/datasets"; import { Authenticator, getSession } from "@app/lib/auth"; import { useRegisterUnloadHandlers } from "@app/lib/front"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; app: AppType; diff --git a/front/pages/w/[wId]/a/[aId]/execute/index.tsx b/front/pages/w/[wId]/a/[aId]/execute/index.tsx index 422f047acc87..fcc75d4f2a94 100644 --- a/front/pages/w/[wId]/a/[aId]/execute/index.tsx +++ b/front/pages/w/[wId]/a/[aId]/execute/index.tsx @@ -40,9 +40,9 @@ import { getDatasetTypes, getValueType, } from "@app/lib/datasets"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { useSavedRunStatus } from "@app/lib/swr"; import { classNames } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const CodeEditor = dynamic( () => import("@uiw/react-textarea-code-editor").then((mod) => mod.default), @@ -57,7 +57,7 @@ type Event = { }; }; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; app: AppType; diff --git a/front/pages/w/[wId]/a/[aId]/index.tsx b/front/pages/w/[wId]/a/[aId]/index.tsx index 9265e362e0ea..962950a382f4 100644 --- a/front/pages/w/[wId]/a/[aId]/index.tsx +++ b/front/pages/w/[wId]/a/[aId]/index.tsx @@ -35,6 +35,7 @@ import { import { getApp } from "@app/lib/api/app"; import { Authenticator, getSession } from "@app/lib/auth"; import { extractConfig } from "@app/lib/config"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { addBlock, deleteBlock, @@ -42,11 +43,10 @@ import { moveBlockUp, } from "@app/lib/specification"; import { useSavedRunStatus } from "@app/lib/swr"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { URL = "", GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ user: UserType | null; owner: WorkspaceType; subscription: SubscriptionType; diff --git a/front/pages/w/[wId]/a/[aId]/runs/[runId]/index.tsx b/front/pages/w/[wId]/a/[aId]/runs/[runId]/index.tsx index acac65223a5d..98601691065e 100644 --- a/front/pages/w/[wId]/a/[aId]/runs/[runId]/index.tsx +++ b/front/pages/w/[wId]/a/[aId]/runs/[runId]/index.tsx @@ -17,11 +17,11 @@ import { import { getApp } from "@app/lib/api/app"; import { getRun } from "@app/lib/api/run"; import { Authenticator, getSession } from "@app/lib/auth"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; diff --git a/front/pages/w/[wId]/a/[aId]/runs/index.tsx b/front/pages/w/[wId]/a/[aId]/runs/index.tsx index 913f571bb658..edc831ba81bf 100644 --- a/front/pages/w/[wId]/a/[aId]/runs/index.tsx +++ b/front/pages/w/[wId]/a/[aId]/runs/index.tsx @@ -16,13 +16,13 @@ import { } from "@app/components/sparkle/navigation"; import { getApp } from "@app/lib/api/app"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { useRuns } from "@app/lib/swr"; import { classNames, timeAgoFrom } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; diff --git a/front/pages/w/[wId]/a/[aId]/settings.tsx b/front/pages/w/[wId]/a/[aId]/settings.tsx index bd1bc659fc72..fafb7de13a2e 100644 --- a/front/pages/w/[wId]/a/[aId]/settings.tsx +++ b/front/pages/w/[wId]/a/[aId]/settings.tsx @@ -17,12 +17,12 @@ import { } from "@app/components/sparkle/navigation"; import { getApp } from "@app/lib/api/app"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { classNames, MODELS_STRING_MAX_LENGTH } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; app: AppType; diff --git a/front/pages/w/[wId]/a/[aId]/specification.tsx b/front/pages/w/[wId]/a/[aId]/specification.tsx index 5dd1170a8e5b..eb64c30fcb2f 100644 --- a/front/pages/w/[wId]/a/[aId]/specification.tsx +++ b/front/pages/w/[wId]/a/[aId]/specification.tsx @@ -12,13 +12,13 @@ import { } from "@app/components/sparkle/navigation"; import { getApp } from "@app/lib/api/app"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { dumpSpecification } from "@app/lib/specification"; import logger from "@app/logger/logger"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; diff --git a/front/pages/w/[wId]/a/index.tsx b/front/pages/w/[wId]/a/index.tsx index da2970091b17..8f8426afd2cc 100644 --- a/front/pages/w/[wId]/a/index.tsx +++ b/front/pages/w/[wId]/a/index.tsx @@ -26,14 +26,14 @@ import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getApps } from "@app/lib/api/app"; import { Authenticator, getSession } from "@app/lib/auth"; import { useSubmitFunction } from "@app/lib/client/utils"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { modelProviders, serviceProviders } from "@app/lib/providers"; import { useKeys, useProviders } from "@app/lib/swr"; import { classNames, timeAgoFrom } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; apps: AppType[]; diff --git a/front/pages/w/[wId]/a/new.tsx b/front/pages/w/[wId]/a/new.tsx index 79c40f4cd54a..93f922a15aff 100644 --- a/front/pages/w/[wId]/a/new.tsx +++ b/front/pages/w/[wId]/a/new.tsx @@ -11,12 +11,12 @@ import React, { useCallback, useEffect, useState } from "react"; import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { classNames, MODELS_STRING_MAX_LENGTH } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; gaTrackingId: string; diff --git a/front/pages/w/[wId]/assistant/[cId]/index.tsx b/front/pages/w/[wId]/assistant/[cId]/index.tsx index fb381930f440..7043a58bed5a 100644 --- a/front/pages/w/[wId]/assistant/[cId]/index.tsx +++ b/front/pages/w/[wId]/assistant/[cId]/index.tsx @@ -18,13 +18,13 @@ import { AssistantSidebarMenu } from "@app/components/assistant/conversation/Sid import AppLayout from "@app/components/sparkle/AppLayout"; import { SendNotificationsContext } from "@app/components/sparkle/Notification"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { useConversation } from "@app/lib/swr"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; import { LimitReachedPopup } from "@app/pages/w/[wId]/assistant/new"; const { URL = "", GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ user: UserType; owner: WorkspaceType; subscription: SubscriptionType; diff --git a/front/pages/w/[wId]/assistant/assistants.tsx b/front/pages/w/[wId]/assistant/assistants.tsx index 0a584126dfcf..532f12387348 100644 --- a/front/pages/w/[wId]/assistant/assistants.tsx +++ b/front/pages/w/[wId]/assistant/assistants.tsx @@ -23,13 +23,13 @@ import { SCOPE_INFO } from "@app/components/assistant/Sharing"; import AppLayout from "@app/components/sparkle/AppLayout"; import { AppLayoutSimpleCloseTitle } from "@app/components/sparkle/AppLayoutTitle"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { useAgentConfigurations } from "@app/lib/swr"; import { subFilter } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; gaTrackingId: string; diff --git a/front/pages/w/[wId]/assistant/gallery.tsx b/front/pages/w/[wId]/assistant/gallery.tsx index 374dca7b9968..7c5649e551ac 100644 --- a/front/pages/w/[wId]/assistant/gallery.tsx +++ b/front/pages/w/[wId]/assistant/gallery.tsx @@ -28,13 +28,13 @@ import { TryAssistantModal } from "@app/components/assistant/TryAssistantModal"; import AppLayout, { appLayoutBack } from "@app/components/sparkle/AppLayout"; import { AppLayoutSimpleCloseTitle } from "@app/components/sparkle/AppLayoutTitle"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { useAgentConfigurations } from "@app/lib/swr"; import { subFilter } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ user: UserType; owner: WorkspaceType; plan: PlanType | null; diff --git a/front/pages/w/[wId]/assistant/new.tsx b/front/pages/w/[wId]/assistant/new.tsx index 6eeaadd2029b..20704d799147 100644 --- a/front/pages/w/[wId]/assistant/new.tsx +++ b/front/pages/w/[wId]/assistant/new.tsx @@ -39,12 +39,12 @@ import { compareAgentsForSort } from "@app/lib/assistant"; import { Authenticator, getSession } from "@app/lib/auth"; import { getRandomGreetingForName } from "@app/lib/client/greetings"; import { useSubmitFunction } from "@app/lib/client/utils"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { useAgentConfigurations } from "@app/lib/swr"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ user: UserType; isBuilder: boolean; subscription: SubscriptionType; diff --git a/front/pages/w/[wId]/builder/assistants/[aId]/index.tsx b/front/pages/w/[wId]/builder/assistants/[aId]/index.tsx index 9c26ee48a373..2baddea9e3b6 100644 --- a/front/pages/w/[wId]/builder/assistants/[aId]/index.tsx +++ b/front/pages/w/[wId]/builder/assistants/[aId]/index.tsx @@ -26,11 +26,11 @@ import { getApps } from "@app/lib/api/app"; import { getAgentConfiguration } from "@app/lib/api/assistant/configuration"; import { getDataSources } from "@app/lib/api/data_sources"; import { Authenticator, getSession } from "@app/lib/auth"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "", URL = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; plan: PlanType; diff --git a/front/pages/w/[wId]/builder/assistants/dust.tsx b/front/pages/w/[wId]/builder/assistants/dust.tsx index 369de3b0d5cc..44f69ff3177c 100644 --- a/front/pages/w/[wId]/builder/assistants/dust.tsx +++ b/front/pages/w/[wId]/builder/assistants/dust.tsx @@ -25,12 +25,12 @@ import { SendNotificationsContext } from "@app/components/sparkle/Notification"; import { Authenticator, getSession } from "@app/lib/auth"; import { CONNECTOR_CONFIGURATIONS } from "@app/lib/connector_providers"; import { getDisplayNameForDataSource } from "@app/lib/data_sources"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { useAgentConfigurations, useDataSources } from "@app/lib/swr"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; gaTrackingId: string; diff --git a/front/pages/w/[wId]/builder/assistants/index.tsx b/front/pages/w/[wId]/builder/assistants/index.tsx index 6f0523a25c2a..12be3185b0d8 100644 --- a/front/pages/w/[wId]/builder/assistants/index.tsx +++ b/front/pages/w/[wId]/builder/assistants/index.tsx @@ -32,13 +32,13 @@ import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { compareAgentsForSort } from "@app/lib/assistant"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { useAgentConfigurations } from "@app/lib/swr"; import { classNames, subFilter } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; tabScope: AgentConfigurationScope; diff --git a/front/pages/w/[wId]/builder/assistants/new.tsx b/front/pages/w/[wId]/builder/assistants/new.tsx index 0fa110453a03..d5decf626839 100644 --- a/front/pages/w/[wId]/builder/assistants/new.tsx +++ b/front/pages/w/[wId]/builder/assistants/new.tsx @@ -26,11 +26,11 @@ import { getApps } from "@app/lib/api/app"; import { getAgentConfiguration } from "@app/lib/api/assistant/configuration"; import { getDataSources } from "@app/lib/api/data_sources"; import { Authenticator, getSession } from "@app/lib/auth"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "", URL = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; plan: PlanType; diff --git a/front/pages/w/[wId]/builder/data-sources/[name]/edit-public-url.tsx b/front/pages/w/[wId]/builder/data-sources/[name]/edit-public-url.tsx index 68717082fdb7..430966bb9709 100644 --- a/front/pages/w/[wId]/builder/data-sources/[name]/edit-public-url.tsx +++ b/front/pages/w/[wId]/builder/data-sources/[name]/edit-public-url.tsx @@ -10,12 +10,12 @@ import type { InferGetServerSidePropsType } from "next"; import WebsiteConfiguration from "@app/components/data_source/WebsiteConfiguration"; import { getDataSource, getDataSources } from "@app/lib/api/data_sources"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import logger from "@app/logger/logger"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; dataSources: DataSourceType[]; diff --git a/front/pages/w/[wId]/builder/data-sources/[name]/index.tsx b/front/pages/w/[wId]/builder/data-sources/[name]/index.tsx index 39928c1c59f0..a0ba5b3282f8 100644 --- a/front/pages/w/[wId]/builder/data-sources/[name]/index.tsx +++ b/front/pages/w/[wId]/builder/data-sources/[name]/index.tsx @@ -47,10 +47,10 @@ import { buildConnectionId } from "@app/lib/connector_connection_id"; import { CONNECTOR_CONFIGURATIONS } from "@app/lib/connector_providers"; import { getDisplayNameForDocument } from "@app/lib/data_sources"; import { githubAuth } from "@app/lib/github_auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { useConnectorConfig, useDocuments, useTables } from "@app/lib/swr"; import { timeAgoFrom } from "@app/lib/utils"; import logger from "@app/logger/logger"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "", @@ -63,7 +63,7 @@ const { NANGO_SLACK_CONNECTOR_ID = "", } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; plan: PlanType; diff --git a/front/pages/w/[wId]/builder/data-sources/[name]/search.tsx b/front/pages/w/[wId]/builder/data-sources/[name]/search.tsx index a0d687844bc8..25604616b7d4 100644 --- a/front/pages/w/[wId]/builder/data-sources/[name]/search.tsx +++ b/front/pages/w/[wId]/builder/data-sources/[name]/search.tsx @@ -15,12 +15,12 @@ import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getDataSource } from "@app/lib/api/data_sources"; import { Authenticator, getSession } from "@app/lib/auth"; import { getDisplayNameForDocument } from "@app/lib/data_sources"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { classNames, timeAgoFrom } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; dataSource: DataSourceType; diff --git a/front/pages/w/[wId]/builder/data-sources/[name]/settings.tsx b/front/pages/w/[wId]/builder/data-sources/[name]/settings.tsx index 1fefde1f6958..b9aa97691de9 100644 --- a/front/pages/w/[wId]/builder/data-sources/[name]/settings.tsx +++ b/front/pages/w/[wId]/builder/data-sources/[name]/settings.tsx @@ -17,12 +17,12 @@ import { AppLayoutSimpleSaveCancelTitle } from "@app/components/sparkle/AppLayou import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getDataSource } from "@app/lib/api/data_sources"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; dataSource: DataSourceType; diff --git a/front/pages/w/[wId]/builder/data-sources/[name]/tables/upsert.tsx b/front/pages/w/[wId]/builder/data-sources/[name]/tables/upsert.tsx index 356b534945cc..9c20e3eeae26 100644 --- a/front/pages/w/[wId]/builder/data-sources/[name]/tables/upsert.tsx +++ b/front/pages/w/[wId]/builder/data-sources/[name]/tables/upsert.tsx @@ -28,14 +28,14 @@ import { SendNotificationsContext } from "@app/components/sparkle/Notification"; import { getDataSource } from "@app/lib/api/data_sources"; import { Authenticator, getSession } from "@app/lib/auth"; import { handleFileUploadToText } from "@app/lib/client/handle_file_upload"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { useTable } from "@app/lib/swr"; import { classNames } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; import type { UpsertTableFromCsvRequestBody } from "@app/pages/api/w/[wId]/data_sources/[name]/tables/csv"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; diff --git a/front/pages/w/[wId]/builder/data-sources/[name]/upsert.tsx b/front/pages/w/[wId]/builder/data-sources/[name]/upsert.tsx index 721396a11a6b..d6ddca0edfb1 100644 --- a/front/pages/w/[wId]/builder/data-sources/[name]/upsert.tsx +++ b/front/pages/w/[wId]/builder/data-sources/[name]/upsert.tsx @@ -29,12 +29,12 @@ import { SendNotificationsContext } from "@app/components/sparkle/Notification"; import { getDataSource } from "@app/lib/api/data_sources"; import { Authenticator, getSession } from "@app/lib/auth"; import { handleFileUploadToText } from "@app/lib/client/handle_file_upload"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; plan: PlanType; diff --git a/front/pages/w/[wId]/builder/data-sources/managed.tsx b/front/pages/w/[wId]/builder/data-sources/managed.tsx index e44d64d84c6d..0abd0a5e3c87 100644 --- a/front/pages/w/[wId]/builder/data-sources/managed.tsx +++ b/front/pages/w/[wId]/builder/data-sources/managed.tsx @@ -35,9 +35,9 @@ import { Authenticator, getSession } from "@app/lib/auth"; import { buildConnectionId } from "@app/lib/connector_connection_id"; import { CONNECTOR_CONFIGURATIONS } from "@app/lib/connector_providers"; import { githubAuth } from "@app/lib/github_auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { timeAgoFrom } from "@app/lib/utils"; import logger from "@app/logger/logger"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "", @@ -73,7 +73,7 @@ const REDIRECT_TO_EDIT_PERMISSIONS = [ "intercom", ]; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; diff --git a/front/pages/w/[wId]/builder/data-sources/new-public-url.tsx b/front/pages/w/[wId]/builder/data-sources/new-public-url.tsx index 9143493e224a..3dd462be475f 100644 --- a/front/pages/w/[wId]/builder/data-sources/new-public-url.tsx +++ b/front/pages/w/[wId]/builder/data-sources/new-public-url.tsx @@ -8,11 +8,11 @@ import type { InferGetServerSidePropsType } from "next"; import WebsiteConfiguration from "@app/components/data_source/WebsiteConfiguration"; import { getDataSources } from "@app/lib/api/data_sources"; import { Authenticator, getSession } from "@app/lib/auth"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; dataSources: DataSourceType[]; diff --git a/front/pages/w/[wId]/builder/data-sources/new.tsx b/front/pages/w/[wId]/builder/data-sources/new.tsx index 35fe768266cd..b5ddf4294113 100644 --- a/front/pages/w/[wId]/builder/data-sources/new.tsx +++ b/front/pages/w/[wId]/builder/data-sources/new.tsx @@ -12,12 +12,12 @@ import { AppLayoutSimpleSaveCancelTitle } from "@app/components/sparkle/AppLayou import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getDataSources } from "@app/lib/api/data_sources"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; dataSources: DataSourceType[]; diff --git a/front/pages/w/[wId]/builder/data-sources/public-urls.tsx b/front/pages/w/[wId]/builder/data-sources/public-urls.tsx index ced61cce5fdb..1525f3ec8953 100644 --- a/front/pages/w/[wId]/builder/data-sources/public-urls.tsx +++ b/front/pages/w/[wId]/builder/data-sources/public-urls.tsx @@ -26,8 +26,8 @@ import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getDataSources } from "@app/lib/api/data_sources"; import { Authenticator, getSession } from "@app/lib/auth"; import { useSubmitFunction } from "@app/lib/client/utils"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import logger from "@app/logger/logger"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; @@ -35,7 +35,7 @@ type DataSourceWithConnector = DataSourceType & { connector: ConnectorType; }; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; plan: PlanType; diff --git a/front/pages/w/[wId]/builder/data-sources/static.tsx b/front/pages/w/[wId]/builder/data-sources/static.tsx index acef9ec705a7..2a502e787c35 100644 --- a/front/pages/w/[wId]/builder/data-sources/static.tsx +++ b/front/pages/w/[wId]/builder/data-sources/static.tsx @@ -20,11 +20,11 @@ import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getDataSources } from "@app/lib/api/data_sources"; import { Authenticator, getSession } from "@app/lib/auth"; import { useSubmitFunction } from "@app/lib/client/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; plan: PlanType; diff --git a/front/pages/w/[wId]/index.tsx b/front/pages/w/[wId]/index.tsx index c2fb8b253d02..58b6191f58f3 100644 --- a/front/pages/w/[wId]/index.tsx +++ b/front/pages/w/[wId]/index.tsx @@ -1,7 +1,7 @@ import { Authenticator, getSession } from "@app/lib/auth"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; -export const getServerSideProps = withGetServerSidePropsLogging( +export const getServerSideProps = withGetServerSidePropsRequirements( async (context) => { const session = await getSession(context.req, context.res); const auth = await Authenticator.fromSession( diff --git a/front/pages/w/[wId]/join.tsx b/front/pages/w/[wId]/join.tsx index ce2b8ad47a1b..a026bc14fee5 100644 --- a/front/pages/w/[wId]/join.tsx +++ b/front/pages/w/[wId]/join.tsx @@ -10,7 +10,7 @@ import { getWorkspaceInfos, getWorkspaceVerifiedDomain, } from "@app/lib/api/workspace"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; const { URL = "", GA_TRACKING_ID = "" } = process.env; @@ -38,76 +38,84 @@ type OnboardingType = | "domain_conversation_link" | "domain_invite_link"; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ onboardingType: OnboardingType; workspace: LightWorkspaceType; signUpCallbackUrl: string; gaTrackingId: string; baseUrl: string; -}>(async (context) => { - const wId = context.query.wId as string; - if (!wId) { - return { - notFound: true, - }; - } - const workspace = await getWorkspaceInfos(wId); - if (!workspace) { - return { - notFound: true, - }; - } - const workspaceDomain = await getWorkspaceVerifiedDomain(workspace); - - const cId = typeof context.query.cId === "string" ? context.query.cId : null; - const token = typeof context.query.t === "string" ? context.query.t : null; - let onboardingType: OnboardingType | null = null; +}>( + async (context) => { + const wId = context.query.wId as string; + if (!wId) { + return { + notFound: true, + }; + } + const workspace = await getWorkspaceInfos(wId); + if (!workspace) { + return { + notFound: true, + }; + } + const workspaceDomain = await getWorkspaceVerifiedDomain(workspace); - if (cId) { - onboardingType = "domain_conversation_link"; - } else if (token) { - onboardingType = "email_invite"; - } else { - onboardingType = "domain_invite_link"; - } + const cId = + typeof context.query.cId === "string" ? context.query.cId : null; + const token = typeof context.query.t === "string" ? context.query.t : null; + let onboardingType: OnboardingType | null = null; - // Redirect to 404 if in a flow where we need a verified domain and there is none. - if ( - !workspaceDomain?.domainAutoJoinEnabled && - ["domain_conversation_link", "domain_invite_link"].includes(onboardingType) - ) { - return { - notFound: true, - }; - } + if (cId) { + onboardingType = "domain_conversation_link"; + } else if (token) { + onboardingType = "email_invite"; + } else { + onboardingType = "domain_invite_link"; + } - let signUpCallbackUrl: string | undefined = undefined; - switch (onboardingType) { - case "domain_conversation_link": - signUpCallbackUrl = `/api/login?wId=${wId}&cId=${cId}&join=true`; - break; - case "email_invite": - signUpCallbackUrl = `/api/login?inviteToken=${token}`; - break; - case "domain_invite_link": - signUpCallbackUrl = `/api/login?wId=${wId}`; - break; - default: + // Redirect to 404 if in a flow where we need a verified domain and there is none. + if ( + !workspaceDomain?.domainAutoJoinEnabled && + ["domain_conversation_link", "domain_invite_link"].includes( + onboardingType + ) + ) { return { notFound: true, }; - } + } + + let signUpCallbackUrl: string | undefined = undefined; + switch (onboardingType) { + case "domain_conversation_link": + signUpCallbackUrl = `/api/login?wId=${wId}&cId=${cId}&join=true`; + break; + case "email_invite": + signUpCallbackUrl = `/api/login?inviteToken=${token}`; + break; + case "domain_invite_link": + signUpCallbackUrl = `/api/login?wId=${wId}`; + break; + default: + return { + notFound: true, + }; + } - return { - props: { - onboardingType: onboardingType, - workspace: workspace, - signUpCallbackUrl: signUpCallbackUrl, - baseUrl: URL, - gaTrackingId: GA_TRACKING_ID, - }, - }; -}); + return { + props: { + onboardingType: onboardingType, + workspace: workspace, + signUpCallbackUrl: signUpCallbackUrl, + baseUrl: URL, + gaTrackingId: GA_TRACKING_ID, + }, + }; + }, + { + requireAuth: false, + } +); export default function Join({ onboardingType, diff --git a/front/pages/w/[wId]/members/index.tsx b/front/pages/w/[wId]/members/index.tsx index fffd73cdd85c..ae828a9d4aa3 100644 --- a/front/pages/w/[wId]/members/index.tsx +++ b/front/pages/w/[wId]/members/index.tsx @@ -37,16 +37,16 @@ import { getWorkspaceVerifiedDomain, } from "@app/lib/api/workspace"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { isUpgraded } from "@app/lib/plans/plan_codes"; import { useMembers, useWorkspaceInvitations } from "@app/lib/swr"; import { classNames, isEmailValid } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; const CLOSING_ANIMATION_DURATION = 200; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ user: UserType; owner: WorkspaceType; subscription: SubscriptionType; diff --git a/front/pages/w/[wId]/subscription/index.tsx b/front/pages/w/[wId]/subscription/index.tsx index 98c0519231d6..a7b6cc2cc9cf 100644 --- a/front/pages/w/[wId]/subscription/index.tsx +++ b/front/pages/w/[wId]/subscription/index.tsx @@ -20,6 +20,7 @@ import { subNavigationAdmin } from "@app/components/sparkle/navigation"; import { SendNotificationsContext } from "@app/components/sparkle/Notification"; import { Authenticator, getSession } from "@app/lib/auth"; import { useSubmitFunction } from "@app/lib/client/utils"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { FREE_TEST_PLAN_CODE, FREE_UPGRADED_PLAN_CODE, @@ -27,11 +28,10 @@ import { PRO_PLAN_SEAT_29_CODE, } from "@app/lib/plans/plan_codes"; import { getPlanInvitation } from "@app/lib/plans/subscription"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; planInvitation: PlanInvitationType | null; diff --git a/front/pages/w/[wId]/subscription/upgrade-enterprise/[secret].tsx b/front/pages/w/[wId]/subscription/upgrade-enterprise/[secret].tsx index 914d2f6b28e1..88db33616223 100644 --- a/front/pages/w/[wId]/subscription/upgrade-enterprise/[secret].tsx +++ b/front/pages/w/[wId]/subscription/upgrade-enterprise/[secret].tsx @@ -1,10 +1,10 @@ import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { Workspace } from "@app/lib/models"; import { PlanInvitation } from "@app/lib/models/plan"; import { getCheckoutUrlForUpgrade } from "@app/lib/plans/subscription"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; -export const getServerSideProps = withGetServerSidePropsLogging( +export const getServerSideProps = withGetServerSidePropsRequirements( async (context) => { const session = await getSession(context.req, context.res); const auth = await Authenticator.fromSession( diff --git a/front/pages/w/[wId]/u/extract/events/[sId]/edit.tsx b/front/pages/w/[wId]/u/extract/events/[sId]/edit.tsx index 52d8d16ee250..2865e015365d 100644 --- a/front/pages/w/[wId]/u/extract/events/[sId]/edit.tsx +++ b/front/pages/w/[wId]/u/extract/events/[sId]/edit.tsx @@ -11,12 +11,12 @@ import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getEventSchema, getExtractedEvent } from "@app/lib/api/extract"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; event: ExtractedEventType; diff --git a/front/pages/w/[wId]/u/extract/index.tsx b/front/pages/w/[wId]/u/extract/index.tsx index c2c8edf3e79b..8952422d37fd 100644 --- a/front/pages/w/[wId]/u/extract/index.tsx +++ b/front/pages/w/[wId]/u/extract/index.tsx @@ -9,11 +9,11 @@ import { useRouter } from "next/router"; import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { useEventSchemas } from "@app/lib/swr"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; diff --git a/front/pages/w/[wId]/u/extract/templates/[sId]/edit.tsx b/front/pages/w/[wId]/u/extract/templates/[sId]/edit.tsx index a5b0d958e3b9..193ed93074c8 100644 --- a/front/pages/w/[wId]/u/extract/templates/[sId]/edit.tsx +++ b/front/pages/w/[wId]/u/extract/templates/[sId]/edit.tsx @@ -8,11 +8,11 @@ import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { ExtractEventSchemaForm } from "@app/components/use/EventSchemaForm"; import { getEventSchema } from "@app/lib/api/extract"; import { Authenticator, getSession } from "@app/lib/auth"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; schema: EventSchemaType; diff --git a/front/pages/w/[wId]/u/extract/templates/[sId]/index.tsx b/front/pages/w/[wId]/u/extract/templates/[sId]/index.tsx index 44aabec22d9d..7b08410051a4 100644 --- a/front/pages/w/[wId]/u/extract/templates/[sId]/index.tsx +++ b/front/pages/w/[wId]/u/extract/templates/[sId]/index.tsx @@ -26,13 +26,13 @@ import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getEventSchema } from "@app/lib/api/extract"; import { Authenticator, getSession } from "@app/lib/auth"; import { CONNECTOR_CONFIGURATIONS } from "@app/lib/connector_providers"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { useExtractedEvents } from "@app/lib/swr"; import { classNames, objectToMarkdown } from "@app/lib/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; schema: EventSchemaType; diff --git a/front/pages/w/[wId]/u/extract/templates/new.tsx b/front/pages/w/[wId]/u/extract/templates/new.tsx index dc33d55d38a6..7c7dd65c78b3 100644 --- a/front/pages/w/[wId]/u/extract/templates/new.tsx +++ b/front/pages/w/[wId]/u/extract/templates/new.tsx @@ -6,11 +6,11 @@ import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { ExtractEventSchemaForm } from "@app/components/use/EventSchemaForm"; import { Authenticator, getSession } from "@app/lib/auth"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; diff --git a/front/pages/w/[wId]/welcome.tsx b/front/pages/w/[wId]/welcome.tsx index ee5238668400..d308e0df9bff 100644 --- a/front/pages/w/[wId]/welcome.tsx +++ b/front/pages/w/[wId]/welcome.tsx @@ -8,14 +8,14 @@ import OnboardingLayout from "@app/components/sparkle/OnboardingLayout"; import { getUserMetadata } from "@app/lib/api/user"; import { Authenticator, getSession } from "@app/lib/auth"; import { useSubmitFunction } from "@app/lib/client/utils"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; const { URL = "", GA_TRACKING_ID = "" } = process.env; const ADMIN_YOUTUBE_ID = "f9n4mqBX2aw"; const MEMBER_YOUTUBE_ID = null; // We don't have the video yet. -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ user: UserType; owner: WorkspaceType; isAdmin: boolean; diff --git a/front/pages/w/[wId]/workspace/index.tsx b/front/pages/w/[wId]/workspace/index.tsx index 0efb59f8d21f..00d57b7b7e6c 100644 --- a/front/pages/w/[wId]/workspace/index.tsx +++ b/front/pages/w/[wId]/workspace/index.tsx @@ -15,12 +15,12 @@ import { useCallback, useEffect, useState } from "react"; import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationAdmin } from "@app/components/sparkle/navigation"; import { Authenticator, getSession } from "@app/lib/auth"; +import { withGetServerSidePropsRequirements } from "@app/lib/iam/session"; import { useWorkspaceAnalytics } from "@app/lib/swr"; -import { withGetServerSidePropsLogging } from "@app/logger/withlogging"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withGetServerSidePropsLogging<{ +export const getServerSideProps = withGetServerSidePropsRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; gaTrackingId: string;