From c572d8bb6869b3243d5b479bd2d59b25fbdf1a68 Mon Sep 17 00:00:00 2001 From: Flavien David Date: Fri, 8 Mar 2024 14:21:40 +0100 Subject: [PATCH 1/6] Augment session wrapper for SSR --- front/lib/iam/session.ts | 81 ++++++++++++++++++++++++++++--------- front/logger/withlogging.ts | 12 +++--- 2 files changed, 68 insertions(+), 25 deletions(-) diff --git a/front/lib/iam/session.ts b/front/lib/iam/session.ts index 7f6324d9708d..4d75b8b21f03 100644 --- a/front/lib/iam/session.ts +++ b/front/lib/iam/session.ts @@ -7,7 +7,7 @@ import type { import type { ParsedUrlQuery } from "querystring"; import { Op } from "sequelize"; -import { getSession } from "@app/lib/auth"; +import { Authenticator, getSession } from "@app/lib/auth"; import type { SessionWithUser } from "@app/lib/iam/provider"; import { isValidSession } from "@app/lib/iam/provider"; import { @@ -84,38 +84,74 @@ export async function getUserFromSession( } interface MakeGetServerSidePropsRequirementsWrapperOptions< - R extends boolean = true + R extends AuthLevel = "user" > { enableLogging?: boolean; - requireAuth: R; + requireAuthLevel: R; } export type CustomGetServerSideProps< Props extends { [key: string]: any } = { [key: string]: any }, Params extends ParsedUrlQuery = ParsedUrlQuery, Preview extends PreviewData = PreviewData, - RequireAuth extends boolean = true + RequireAuthLevel extends AuthLevel = "user" > = ( context: GetServerSidePropsContext, - session: RequireAuth extends true ? SessionWithUser : null + session: RequireAuthLevel extends "none" ? null : SessionWithUser, + auth: RequireAuthLevel extends "none" ? null : Authenticator ) => Promise>; +export type AuthLevel = "none" | "user" | "superuser"; + +async function getAuthenticator( + context: GetServerSidePropsContext, + session: SessionWithUser | null, + requireAuthLevel: AuthLevel +) { + if (!session) { + return null; + } + + const { wId } = context.params ?? {}; + if (typeof wId !== "string") { + return null; + } + + switch (requireAuthLevel) { + case "user": + return Authenticator.fromSession(session, wId); + + case "superuser": + return Authenticator.fromSuperUserSession(session, wId); + + default: + return null; + } +} + export function makeGetServerSidePropsRequirementsWrapper< - RequireAuth extends boolean = true + RequireAuthLevel extends AuthLevel = "user" >({ enableLogging = true, - requireAuth, -}: MakeGetServerSidePropsRequirementsWrapperOptions) { + requireAuthLevel, +}: MakeGetServerSidePropsRequirementsWrapperOptions) { return ( - getServerSideProps: CustomGetServerSideProps + getServerSideProps: CustomGetServerSideProps ) => { return async ( context: GetServerSidePropsContext ) => { - const session = requireAuth - ? await getSession(context.req, context.res) - : null; - if (requireAuth && (!session || !isValidSession(session))) { + const session = + requireAuthLevel !== "none" + ? await getSession(context.req, context.res) + : null; + const auth = await getAuthenticator(context, session, requireAuthLevel); + + if ( + requireAuthLevel !== "none" && + (!session || !isValidSession(session)) + ) { + // TODO: Check if the user has a workspace. return { redirect: { permanent: false, @@ -125,21 +161,28 @@ export function makeGetServerSidePropsRequirementsWrapper< }; } - const userSession = session as RequireAuth extends true - ? SessionWithUser - : null; + const userSession = session as RequireAuthLevel extends "none" + ? null + : SessionWithUser; + const currentAuth = auth as RequireAuthLevel extends "none" + ? null + : Authenticator; if (enableLogging) { return withGetServerSidePropsLogging(getServerSideProps)( context, - userSession + userSession, + currentAuth ); } - return getServerSideProps(context, userSession); + return getServerSideProps(context, userSession, currentAuth); }; }; } export const withDefaultGetServerSidePropsRequirements = - makeGetServerSidePropsRequirementsWrapper({ requireAuth: true }); + makeGetServerSidePropsRequirementsWrapper({ requireAuthLevel: "user" }); + +export const withSuperUserGetServerSidePropsRequirements = + makeGetServerSidePropsRequirementsWrapper({ requireAuthLevel: "superuser" }); diff --git a/front/logger/withlogging.ts b/front/logger/withlogging.ts index ba02b4ce7d24..afce8d6e794e 100644 --- a/front/logger/withlogging.ts +++ b/front/logger/withlogging.ts @@ -6,7 +6,7 @@ import tracer from "dd-trace"; import StatsD from "hot-shots"; import type { NextApiRequest, NextApiResponse } from "next"; -import type { CustomGetServerSideProps } from "@app/lib/iam/session"; +import type { AuthLevel, CustomGetServerSideProps } from "@app/lib/iam/session"; import logger from "./logger"; @@ -145,11 +145,11 @@ export function apiError( export function withGetServerSidePropsLogging< T extends { [key: string]: any }, - RequireAuth extends boolean = true + RequireAuthLevel extends AuthLevel = "user" >( - getServerSideProps: CustomGetServerSideProps -): CustomGetServerSideProps { - return async (context, session) => { + getServerSideProps: CustomGetServerSideProps +): CustomGetServerSideProps { + return async (context, session, auth) => { const now = new Date(); let route = context.resolvedUrl.split("?")[0]; @@ -161,7 +161,7 @@ export function withGetServerSidePropsLogging< } try { - const res = await getServerSideProps(context, session); + const res = await getServerSideProps(context, session, auth); const elapsed = new Date().getTime() - now.getTime(); From 7bd5282a409a78033cde01830595ddf10c44509b Mon Sep 17 00:00:00 2001 From: Flavien David Date: Fri, 8 Mar 2024 14:39:31 +0100 Subject: [PATCH 2/6] Update all call sites --- front/lib/iam/session.ts | 16 +-- front/logger/withlogging.ts | 4 +- front/pages/index.tsx | 2 +- front/pages/login-error.tsx | 2 +- front/pages/no-workspace.tsx | 6 +- .../poke/[wId]/assistants/[aId]/index.tsx | 12 +-- .../poke/[wId]/data_sources/[name]/index.tsx | 12 +-- .../poke/[wId]/data_sources/[name]/search.tsx | 12 +-- .../poke/[wId]/data_sources/[name]/view.tsx | 11 +- front/pages/poke/[wId]/index.tsx | 12 +-- front/pages/poke/[wId]/memberships.tsx | 12 +-- .../poke/connectors/[connectorId]/index.tsx | 62 +++++------ front/pages/poke/index.tsx | 26 ++--- front/pages/poke/plans.tsx | 26 ++--- front/pages/w/[wId]/a/[aId]/clone.tsx | 12 +-- .../w/[wId]/a/[aId]/datasets/[name]/index.tsx | 12 +-- .../pages/w/[wId]/a/[aId]/datasets/index.tsx | 12 +-- front/pages/w/[wId]/a/[aId]/datasets/new.tsx | 12 +-- front/pages/w/[wId]/a/[aId]/execute/index.tsx | 12 +-- front/pages/w/[wId]/a/[aId]/index.tsx | 12 +-- .../w/[wId]/a/[aId]/runs/[runId]/index.tsx | 13 +-- front/pages/w/[wId]/a/[aId]/runs/index.tsx | 12 +-- front/pages/w/[wId]/a/[aId]/settings.tsx | 12 +-- front/pages/w/[wId]/a/[aId]/specification.tsx | 12 +-- front/pages/w/[wId]/a/index.tsx | 12 +-- front/pages/w/[wId]/a/new.tsx | 12 +-- front/pages/w/[wId]/assistant/[cId]/index.tsx | 12 +-- front/pages/w/[wId]/assistant/assistants.tsx | 12 +-- front/pages/w/[wId]/assistant/gallery.tsx | 12 +-- front/pages/w/[wId]/assistant/new.tsx | 12 +-- .../[wId]/builder/assistants/[aId]/index.tsx | 12 +-- .../pages/w/[wId]/builder/assistants/dust.tsx | 12 +-- .../w/[wId]/builder/assistants/index.tsx | 12 +-- .../pages/w/[wId]/builder/assistants/new.tsx | 12 +-- .../data-sources/[name]/edit-public-url.tsx | 12 +-- .../builder/data-sources/[name]/index.tsx | 13 +-- .../builder/data-sources/[name]/search.tsx | 12 +-- .../builder/data-sources/[name]/settings.tsx | 12 +-- .../data-sources/[name]/tables/upsert.tsx | 12 +-- .../builder/data-sources/[name]/upsert.tsx | 12 +-- .../w/[wId]/builder/data-sources/managed.tsx | 11 +- .../builder/data-sources/new-public-url.tsx | 12 +-- .../w/[wId]/builder/data-sources/new.tsx | 4 +- .../builder/data-sources/public-urls.tsx | 12 +-- .../w/[wId]/builder/data-sources/static.tsx | 12 +-- front/pages/w/[wId]/index.tsx | 35 +++--- front/pages/w/[wId]/join.tsx | 2 +- front/pages/w/[wId]/members/index.tsx | 11 +- front/pages/w/[wId]/subscription/index.tsx | 12 +-- .../upgrade-enterprise/[secret].tsx | 101 ++++++++---------- .../w/[wId]/u/extract/events/[sId]/edit.tsx | 12 +-- front/pages/w/[wId]/u/extract/index.tsx | 12 +-- .../[wId]/u/extract/templates/[sId]/edit.tsx | 12 +-- .../[wId]/u/extract/templates/[sId]/index.tsx | 11 +- .../pages/w/[wId]/u/extract/templates/new.tsx | 12 +-- front/pages/w/[wId]/welcome.tsx | 12 +-- front/pages/w/[wId]/workspace/index.tsx | 12 +-- 57 files changed, 265 insertions(+), 559 deletions(-) diff --git a/front/lib/iam/session.ts b/front/lib/iam/session.ts index 4d75b8b21f03..c16e3feb3a17 100644 --- a/front/lib/iam/session.ts +++ b/front/lib/iam/session.ts @@ -97,8 +97,8 @@ export type CustomGetServerSideProps< RequireAuthLevel extends AuthLevel = "user" > = ( context: GetServerSidePropsContext, - session: RequireAuthLevel extends "none" ? null : SessionWithUser, - auth: RequireAuthLevel extends "none" ? null : Authenticator + auth: RequireAuthLevel extends "none" ? null : Authenticator, + session: RequireAuthLevel extends "none" ? null : SessionWithUser ) => Promise>; export type AuthLevel = "none" | "user" | "superuser"; @@ -164,25 +164,25 @@ export function makeGetServerSidePropsRequirementsWrapper< const userSession = session as RequireAuthLevel extends "none" ? null : SessionWithUser; - const currentAuth = auth as RequireAuthLevel extends "none" + const userAuth = auth as RequireAuthLevel extends "none" ? null : Authenticator; if (enableLogging) { return withGetServerSidePropsLogging(getServerSideProps)( context, - userSession, - currentAuth + userAuth, + userSession ); } - return getServerSideProps(context, userSession, currentAuth); + return getServerSideProps(context, userAuth, userSession); }; }; } -export const withDefaultGetServerSidePropsRequirements = +export const withDefaultUserAuthRequirements = makeGetServerSidePropsRequirementsWrapper({ requireAuthLevel: "user" }); -export const withSuperUserGetServerSidePropsRequirements = +export const withSuperUserAuthRequirements = makeGetServerSidePropsRequirementsWrapper({ requireAuthLevel: "superuser" }); diff --git a/front/logger/withlogging.ts b/front/logger/withlogging.ts index afce8d6e794e..f456dfa953d5 100644 --- a/front/logger/withlogging.ts +++ b/front/logger/withlogging.ts @@ -149,7 +149,7 @@ export function withGetServerSidePropsLogging< >( getServerSideProps: CustomGetServerSideProps ): CustomGetServerSideProps { - return async (context, session, auth) => { + return async (context, auth, session) => { const now = new Date(); let route = context.resolvedUrl.split("?")[0]; @@ -161,7 +161,7 @@ export function withGetServerSidePropsLogging< } try { - const res = await getServerSideProps(context, session, auth); + const res = await getServerSideProps(context, auth, session); const elapsed = new Date().getTime() - now.getTime(); diff --git a/front/pages/index.tsx b/front/pages/index.tsx index 420a7f8bbd06..d43a0fdf7a0f 100644 --- a/front/pages/index.tsx +++ b/front/pages/index.tsx @@ -55,7 +55,7 @@ import { classNames } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; export const getServerSideProps = makeGetServerSidePropsRequirementsWrapper({ - requireAuth: false, + requireAuthLevel: "none", })<{ gaTrackingId: string; }>(async (context) => { diff --git a/front/pages/login-error.tsx b/front/pages/login-error.tsx index c2368a27b72c..723734869350 100644 --- a/front/pages/login-error.tsx +++ b/front/pages/login-error.tsx @@ -7,7 +7,7 @@ import { makeGetServerSidePropsRequirementsWrapper } from "@app/lib/iam/session" const { GA_TRACKING_ID = "" } = process.env; export const getServerSideProps = makeGetServerSidePropsRequirementsWrapper({ - requireAuth: false, + requireAuthLevel: "none", })<{ domain: string | null; gaTrackingId: string; diff --git a/front/pages/no-workspace.tsx b/front/pages/no-workspace.tsx index b088835ef38e..b97cc5b5e5ee 100644 --- a/front/pages/no-workspace.tsx +++ b/front/pages/no-workspace.tsx @@ -11,7 +11,7 @@ import { useRouter } from "next/router"; import { getUserFromSession, - withDefaultGetServerSidePropsRequirements, + withDefaultUserAuthRequirements, } from "@app/lib/iam/session"; import { Membership, Workspace, WorkspaceHasDomain } from "@app/lib/models"; import logger from "@app/logger/logger"; @@ -56,12 +56,12 @@ async function fetchRevokedWorkspace( return Workspace.findByPk(revokedWorkspaceId); } -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ status: "auto-join-disabled" | "revoked"; userFirstName: string; workspaceName: string; workspaceVerifiedDomain: string | null; -}>(async (context, session) => { +}>(async (context, auth, session) => { const user = await getUserFromSession(session); if (!user) { diff --git a/front/pages/poke/[wId]/assistants/[aId]/index.tsx b/front/pages/poke/[wId]/assistants/[aId]/index.tsx index 3bb628f3a996..0756ed2d155e 100644 --- a/front/pages/poke/[wId]/assistants/[aId]/index.tsx +++ b/front/pages/poke/[wId]/assistants/[aId]/index.tsx @@ -9,17 +9,11 @@ import type { InferGetServerSidePropsType } from "next"; import PokeNavbar from "@app/components/poke/PokeNavbar"; import { getAgentConfigurations } from "@app/lib/api/assistant/configuration"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withSuperUserAuthRequirements<{ agentConfigurations: AgentConfigurationType[]; -}>(async (context, session) => { - const auth = await Authenticator.fromSuperUserSession( - session, - context.params?.wId as string - ); - +}>(async (context, session, auth) => { if (!auth.isDustSuperUser()) { return { notFound: true, diff --git a/front/pages/poke/[wId]/data_sources/[name]/index.tsx b/front/pages/poke/[wId]/data_sources/[name]/index.tsx index d15a6caa066e..ebc7ddaa4fe3 100644 --- a/front/pages/poke/[wId]/data_sources/[name]/index.tsx +++ b/front/pages/poke/[wId]/data_sources/[name]/index.tsx @@ -22,17 +22,16 @@ import { useEffect, useState } from "react"; import { PokePermissionTree } from "@app/components/poke/PokeConnectorPermissionsTree"; import PokeNavbar from "@app/components/poke/PokeNavbar"; import { getDataSource } from "@app/lib/api/data_sources"; -import { Authenticator } from "@app/lib/auth"; import { useSubmitFunction } from "@app/lib/client/utils"; import { getDisplayNameForDocument } from "@app/lib/data_sources"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; import { useDocuments } from "@app/lib/swr"; import { formatTimestampToFriendlyDate, timeAgoFrom } from "@app/lib/utils"; import logger from "@app/logger/logger"; const { TEMPORAL_CONNECTORS_NAMESPACE = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withSuperUserAuthRequirements<{ owner: WorkspaceType; dataSource: DataSourceType; coreDataSource: CoreAPIDataSource; @@ -43,12 +42,7 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ githubCodeSyncEnabled: boolean; }; temporalWorkspace: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSuperUserSession( - session, - context.params?.wId as string - ); - +}>(async (context, session, auth) => { const owner = auth.workspace(); if (!owner || !auth.isDustSuperUser()) { diff --git a/front/pages/poke/[wId]/data_sources/[name]/search.tsx b/front/pages/poke/[wId]/data_sources/[name]/search.tsx index b52b55e66463..de3df7024970 100644 --- a/front/pages/poke/[wId]/data_sources/[name]/search.tsx +++ b/front/pages/poke/[wId]/data_sources/[name]/search.tsx @@ -8,20 +8,14 @@ import { useEffect, useState } from "react"; import PokeNavbar from "@app/components/poke/PokeNavbar"; import { getDataSource } from "@app/lib/api/data_sources"; -import { Authenticator } from "@app/lib/auth"; import { getDisplayNameForDocument } from "@app/lib/data_sources"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; import { classNames, timeAgoFrom } from "@app/lib/utils"; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withSuperUserAuthRequirements<{ owner: WorkspaceType; dataSource: DataSourceType; -}>(async (context, session) => { - const auth = await Authenticator.fromSuperUserSession( - session, - context.params?.wId as string - ); - +}>(async (context, session, auth) => { const owner = auth.workspace(); if (!owner || !auth.isAdmin()) { diff --git a/front/pages/poke/[wId]/data_sources/[name]/view.tsx b/front/pages/poke/[wId]/data_sources/[name]/view.tsx index e60f0f34a5fd..06e750d4ec44 100644 --- a/front/pages/poke/[wId]/data_sources/[name]/view.tsx +++ b/front/pages/poke/[wId]/data_sources/[name]/view.tsx @@ -6,18 +6,13 @@ import type { InferGetServerSidePropsType } from "next"; import PokeNavbar from "@app/components/poke/PokeNavbar"; import { getDataSource } from "@app/lib/api/data_sources"; import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; import logger from "@app/logger/logger"; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withSuperUserAuthRequirements<{ document: CoreAPIDocument; -}>(async (context, session) => { - const auth = await Authenticator.fromSuperUserSession( - session, - context.params?.wId as string - ); - +}>(async (context, session, auth) => { if (!auth.isDustSuperUser()) { return { notFound: true, diff --git a/front/pages/poke/[wId]/index.tsx b/front/pages/poke/[wId]/index.tsx index 71001d9f3eae..cb37624c37f3 100644 --- a/front/pages/poke/[wId]/index.tsx +++ b/front/pages/poke/[wId]/index.tsx @@ -35,10 +35,9 @@ import { GLOBAL_AGENTS_SID, orderDatasourceByImportance, } from "@app/lib/assistant"; -import { Authenticator } from "@app/lib/auth"; import { useSubmitFunction } from "@app/lib/client/utils"; import { isDevelopment } from "@app/lib/development"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; import { FREE_TEST_PLAN_CODE, FREE_UPGRADED_PLAN_CODE, @@ -47,7 +46,7 @@ import { import { getPlanInvitation } from "@app/lib/plans/subscription"; import { usePokePlans } from "@app/lib/swr"; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withSuperUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; planInvitation: PlanInvitationType | null; @@ -55,12 +54,7 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ agentConfigurations: AgentConfigurationType[]; whitelistableFeatures: WhitelistableFeature[]; registry: typeof DustProdActionRegistry; -}>(async (context, session) => { - const auth = await Authenticator.fromSuperUserSession( - session, - context.params?.wId as string - ); - +}>(async (context, session, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/poke/[wId]/memberships.tsx b/front/pages/poke/[wId]/memberships.tsx index a91769485912..4c539d44a373 100644 --- a/front/pages/poke/[wId]/memberships.tsx +++ b/front/pages/poke/[wId]/memberships.tsx @@ -10,18 +10,12 @@ import React from "react"; import PokeNavbar from "@app/components/poke/PokeNavbar"; import { getMembers } from "@app/lib/api/workspace"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withSuperUserAuthRequirements<{ owner: WorkspaceType; members: UserTypeWithWorkspaces[]; -}>(async (context, session) => { - const auth = await Authenticator.fromSuperUserSession( - session, - context.params?.wId as string - ); - +}>(async (context, session, auth) => { const owner = auth.workspace(); if (!owner || !auth.isDustSuperUser()) { diff --git a/front/pages/poke/connectors/[connectorId]/index.tsx b/front/pages/poke/connectors/[connectorId]/index.tsx index 56a1e8a58983..8f3ca38afacf 100644 --- a/front/pages/poke/connectors/[connectorId]/index.tsx +++ b/front/pages/poke/connectors/[connectorId]/index.tsx @@ -1,47 +1,43 @@ import type { ConnectorType } from "@dust-tt/types"; import { ConnectorsAPI } from "@dust-tt/types"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; import logger from "@app/logger/logger"; -export const getServerSideProps = - withDefaultGetServerSidePropsRequirements( - async (context, session) => { - const auth = await Authenticator.fromSuperUserSession(session, null); - - if (!auth.isDustSuperUser()) { - return { - notFound: true, - }; - } - - const connectorId = context.params?.connectorId; - - if (!connectorId || typeof connectorId !== "string") { - return { - notFound: true, - }; - } +export const getServerSideProps = withSuperUserAuthRequirements( + async (context, session, auth) => { + if (!auth.isDustSuperUser()) { + return { + notFound: true, + }; + } - const connectorsAPI = new ConnectorsAPI(logger); - const cRes = await connectorsAPI.getConnector(connectorId); - if (cRes.isErr()) { - return { - notFound: true, - }; - } + const connectorId = context.params?.connectorId; - const connector: ConnectorType = cRes.value; + if (!connectorId || typeof connectorId !== "string") { + return { + notFound: true, + }; + } + const connectorsAPI = new ConnectorsAPI(logger); + const cRes = await connectorsAPI.getConnector(connectorId); + if (cRes.isErr()) { return { - redirect: { - destination: `/poke/${connector.workspaceId}/data_sources/${connector.dataSourceName}`, - permanent: false, - }, + notFound: true, }; } - ); + + const connector: ConnectorType = cRes.value; + + return { + redirect: { + destination: `/poke/${connector.workspaceId}/data_sources/${connector.dataSourceName}`, + permanent: false, + }, + }; + } +); export default function Redirect() { return <>; diff --git a/front/pages/poke/index.tsx b/front/pages/poke/index.tsx index ded50bdecad6..0e0ac7503f69 100644 --- a/front/pages/poke/index.tsx +++ b/front/pages/poke/index.tsx @@ -4,26 +4,22 @@ import type { ChangeEvent } from "react"; import React, { useState } from "react"; import PokeNavbar from "@app/components/poke/PokeNavbar"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; import { usePokeWorkspaces } from "@app/lib/swr"; -export const getServerSideProps = - withDefaultGetServerSidePropsRequirements( - async (context, session) => { - const auth = await Authenticator.fromSuperUserSession(session, null); - - if (!auth.isDustSuperUser()) { - return { - notFound: true, - }; - } - +export const getServerSideProps = withSuperUserAuthRequirements( + async (context, session, auth) => { + if (!auth.isDustSuperUser()) { return { - props: {}, + notFound: true, }; } - ); + + return { + props: {}, + }; + } +); const Dashboard = ( _props: InferGetServerSidePropsType diff --git a/front/pages/poke/plans.tsx b/front/pages/poke/plans.tsx index 738b6f60b753..cd0a511b5848 100644 --- a/front/pages/poke/plans.tsx +++ b/front/pages/poke/plans.tsx @@ -22,26 +22,22 @@ import { } from "@app/components/poke/plans/form"; import PokeNavbar from "@app/components/poke/PokeNavbar"; import { SendNotificationsContext } from "@app/components/sparkle/Notification"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; import { usePokePlans } from "@app/lib/swr"; -export const getServerSideProps = - withDefaultGetServerSidePropsRequirements( - async (context, session) => { - const auth = await Authenticator.fromSuperUserSession(session, null); - - if (!auth.isDustSuperUser()) { - return { - notFound: true, - }; - } - +export const getServerSideProps = withSuperUserAuthRequirements( + async (context, session, auth) => { + if (!auth.isDustSuperUser()) { return { - props: {}, + notFound: true, }; } - ); + + return { + props: {}, + }; + } +); const PlansPage = ( _props: InferGetServerSidePropsType diff --git a/front/pages/w/[wId]/a/[aId]/clone.tsx b/front/pages/w/[wId]/a/[aId]/clone.tsx index 34e182d3bc81..5ad6e2a22b42 100644 --- a/front/pages/w/[wId]/a/[aId]/clone.tsx +++ b/front/pages/w/[wId]/a/[aId]/clone.tsx @@ -21,20 +21,19 @@ import { } from "@app/components/sparkle/navigation"; import WorkspacePicker from "@app/components/WorkspacePicker"; import { getApp } from "@app/lib/api/app"; -import { Authenticator } from "@app/lib/auth"; import { getUserFromSession } from "@app/lib/iam/session"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ user: UserTypeWithWorkspaces; owner: WorkspaceType; subscription: SubscriptionType; app: AppType; gaTrackingId: string; -}>(async (context, session) => { +}>(async (context, auth, session) => { // This is a rare case where we need the full user object as we need to know the user available // workspaces to clone the app into. const user = await getUserFromSession(session); @@ -44,11 +43,6 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ }; } - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - const owner = auth.workspace(); const subscription = auth.subscription(); 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 f94b66202dd3..03758f2b8fe1 100644 --- a/front/pages/w/[wId]/a/[aId]/datasets/[name]/index.tsx +++ b/front/pages/w/[wId]/a/[aId]/datasets/[name]/index.tsx @@ -18,13 +18,12 @@ import { } from "@app/components/sparkle/navigation"; import { getApp } from "@app/lib/api/app"; import { getDatasetHash, getDatasetSchema } from "@app/lib/api/datasets"; -import { Authenticator } from "@app/lib/auth"; import { useRegisterUnloadHandlers } from "@app/lib/front"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; @@ -32,12 +31,7 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ dataset: DatasetType; schema: DatasetSchema | null; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/a/[aId]/datasets/index.tsx b/front/pages/w/[wId]/a/[aId]/datasets/index.tsx index b757faf909d7..9d0ca210c2cc 100644 --- a/front/pages/w/[wId]/a/[aId]/datasets/index.tsx +++ b/front/pages/w/[wId]/a/[aId]/datasets/index.tsx @@ -15,25 +15,19 @@ import { } from "@app/components/sparkle/navigation"; import { getApp } from "@app/lib/api/app"; import { getDatasets } from "@app/lib/api/datasets"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; app: AppType; datasets: DatasetType[]; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/a/[aId]/datasets/new.tsx b/front/pages/w/[wId]/a/[aId]/datasets/new.tsx index d79cd3528532..91ea89bd27ba 100644 --- a/front/pages/w/[wId]/a/[aId]/datasets/new.tsx +++ b/front/pages/w/[wId]/a/[aId]/datasets/new.tsx @@ -18,24 +18,18 @@ import { } from "@app/components/sparkle/navigation"; import { getApp } from "@app/lib/api/app"; import { getDatasets } from "@app/lib/api/datasets"; -import { Authenticator } from "@app/lib/auth"; import { useRegisterUnloadHandlers } from "@app/lib/front"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; app: AppType; datasets: DatasetType[]; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/a/[aId]/execute/index.tsx b/front/pages/w/[wId]/a/[aId]/execute/index.tsx index 8b64434baeea..bab70ee31ef4 100644 --- a/front/pages/w/[wId]/a/[aId]/execute/index.tsx +++ b/front/pages/w/[wId]/a/[aId]/execute/index.tsx @@ -33,14 +33,13 @@ import { import { Spinner } from "@app/components/Spinner"; import { getApp } from "@app/lib/api/app"; import { getDatasetHash } from "@app/lib/api/datasets"; -import { Authenticator } from "@app/lib/auth"; import { extractConfig } from "@app/lib/config"; import { checkDatasetData, getDatasetTypes, getValueType, } from "@app/lib/datasets"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { useSavedRunStatus } from "@app/lib/swr"; import { classNames } from "@app/lib/utils"; @@ -57,7 +56,7 @@ type Event = { }; }; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; app: AppType; @@ -65,12 +64,7 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ inputDataset: DatasetType | null; readOnly: boolean; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/a/[aId]/index.tsx b/front/pages/w/[wId]/a/[aId]/index.tsx index 715d3fe9432d..22aceef21c99 100644 --- a/front/pages/w/[wId]/a/[aId]/index.tsx +++ b/front/pages/w/[wId]/a/[aId]/index.tsx @@ -33,9 +33,8 @@ import { subNavigationBuild, } from "@app/components/sparkle/navigation"; import { getApp } from "@app/lib/api/app"; -import { Authenticator } from "@app/lib/auth"; import { extractConfig } from "@app/lib/config"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { addBlock, deleteBlock, @@ -46,7 +45,7 @@ import { useSavedRunStatus } from "@app/lib/swr"; const { URL = "", GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ user: UserType | null; owner: WorkspaceType; subscription: SubscriptionType; @@ -54,12 +53,7 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ url: string; app: AppType; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); 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 88342729bf49..48b6be43907e 100644 --- a/front/pages/w/[wId]/a/[aId]/runs/[runId]/index.tsx +++ b/front/pages/w/[wId]/a/[aId]/runs/[runId]/index.tsx @@ -16,12 +16,11 @@ import { } from "@app/components/sparkle/navigation"; import { getApp } from "@app/lib/api/app"; import { getRun } from "@app/lib/api/run"; -import { Authenticator, getSession } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; @@ -29,13 +28,7 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ run: RunType; spec: SpecificationType; gaTrackingId: string; -}>(async (context) => { - const session = await getSession(context.req, context.res); - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/a/[aId]/runs/index.tsx b/front/pages/w/[wId]/a/[aId]/runs/index.tsx index 635323636035..b263a9392d01 100644 --- a/front/pages/w/[wId]/a/[aId]/runs/index.tsx +++ b/front/pages/w/[wId]/a/[aId]/runs/index.tsx @@ -15,26 +15,20 @@ import { subNavigationBuild, } from "@app/components/sparkle/navigation"; import { getApp } from "@app/lib/api/app"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { useRuns } from "@app/lib/swr"; import { classNames, timeAgoFrom } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; app: AppType; wIdTarget: string | null; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/a/[aId]/settings.tsx b/front/pages/w/[wId]/a/[aId]/settings.tsx index d3a1e24d9a2a..7e8698a48328 100644 --- a/front/pages/w/[wId]/a/[aId]/settings.tsx +++ b/front/pages/w/[wId]/a/[aId]/settings.tsx @@ -16,23 +16,17 @@ import { subNavigationBuild, } from "@app/components/sparkle/navigation"; import { getApp } from "@app/lib/api/app"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { classNames, MODELS_STRING_MAX_LENGTH } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; app: AppType; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); if (!owner || !subscription) { diff --git a/front/pages/w/[wId]/a/[aId]/specification.tsx b/front/pages/w/[wId]/a/[aId]/specification.tsx index 21e74b7f6d00..815d0e114055 100644 --- a/front/pages/w/[wId]/a/[aId]/specification.tsx +++ b/front/pages/w/[wId]/a/[aId]/specification.tsx @@ -11,26 +11,20 @@ import { subNavigationBuild, } from "@app/components/sparkle/navigation"; import { getApp } from "@app/lib/api/app"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { dumpSpecification } from "@app/lib/specification"; import logger from "@app/logger/logger"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; app: AppType; specification: string; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/a/index.tsx b/front/pages/w/[wId]/a/index.tsx index 7416a5218d19..1160ef22ebfe 100644 --- a/front/pages/w/[wId]/a/index.tsx +++ b/front/pages/w/[wId]/a/index.tsx @@ -24,26 +24,20 @@ import SerperSetup from "@app/components/providers/SerperSetup"; import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getApps } from "@app/lib/api/app"; -import { Authenticator } from "@app/lib/auth"; import { useSubmitFunction } from "@app/lib/client/utils"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } 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"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; apps: AppType[]; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/a/new.tsx b/front/pages/w/[wId]/a/new.tsx index a4f243cc617c..47f25dd3e1e3 100644 --- a/front/pages/w/[wId]/a/new.tsx +++ b/front/pages/w/[wId]/a/new.tsx @@ -10,22 +10,16 @@ import React, { useCallback, useEffect, useState } from "react"; import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { classNames, MODELS_STRING_MAX_LENGTH } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/assistant/[cId]/index.tsx b/front/pages/w/[wId]/assistant/[cId]/index.tsx index 92cdf1648091..991da09d69d2 100644 --- a/front/pages/w/[wId]/assistant/[cId]/index.tsx +++ b/front/pages/w/[wId]/assistant/[cId]/index.tsx @@ -17,26 +17,20 @@ import { import { AssistantSidebarMenu } from "@app/components/assistant/conversation/SidebarMenu"; import AppLayout from "@app/components/sparkle/AppLayout"; import { SendNotificationsContext } from "@app/components/sparkle/Notification"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { useConversation } from "@app/lib/swr"; import { LimitReachedPopup } from "@app/pages/w/[wId]/assistant/new"; const { URL = "", GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ user: UserType; owner: WorkspaceType; subscription: SubscriptionType; gaTrackingId: string; baseUrl: string; conversationId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const user = auth.user(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/assistant/assistants.tsx b/front/pages/w/[wId]/assistant/assistants.tsx index 82694bc13e0a..4869b5305eb5 100644 --- a/front/pages/w/[wId]/assistant/assistants.tsx +++ b/front/pages/w/[wId]/assistant/assistants.tsx @@ -22,23 +22,17 @@ import { AssistantSidebarMenu } from "@app/components/assistant/conversation/Sid import { SCOPE_INFO } from "@app/components/assistant/Sharing"; import AppLayout from "@app/components/sparkle/AppLayout"; import { AppLayoutSimpleCloseTitle } from "@app/components/sparkle/AppLayoutTitle"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { useAgentConfigurations } from "@app/lib/swr"; import { subFilter } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); if (!owner || !auth.isUser() || !subscription) { diff --git a/front/pages/w/[wId]/assistant/gallery.tsx b/front/pages/w/[wId]/assistant/gallery.tsx index 7754ee3ada2d..6fa2193695b6 100644 --- a/front/pages/w/[wId]/assistant/gallery.tsx +++ b/front/pages/w/[wId]/assistant/gallery.tsx @@ -27,25 +27,19 @@ import { GalleryAssistantPreviewContainer } from "@app/components/assistant/Gall import { TryAssistantModal } from "@app/components/assistant/TryAssistant"; import AppLayout, { appLayoutBack } from "@app/components/sparkle/AppLayout"; import { AppLayoutSimpleCloseTitle } from "@app/components/sparkle/AppLayoutTitle"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { useAgentConfigurations } from "@app/lib/swr"; import { subFilter } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ user: UserType; owner: WorkspaceType; plan: PlanType | null; subscription: SubscriptionType; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const user = auth.user(); const plan = auth.plan(); diff --git a/front/pages/w/[wId]/assistant/new.tsx b/front/pages/w/[wId]/assistant/new.tsx index 8ce31826c30d..a36b42ec24b3 100644 --- a/front/pages/w/[wId]/assistant/new.tsx +++ b/front/pages/w/[wId]/assistant/new.tsx @@ -38,28 +38,22 @@ import AppLayout from "@app/components/sparkle/AppLayout"; import { SendNotificationsContext } from "@app/components/sparkle/Notification"; import { getAgentConfiguration } from "@app/lib/api/assistant/configuration"; import { compareAgentsForSort } from "@app/lib/assistant"; -import { Authenticator } from "@app/lib/auth"; import { getRandomGreetingForName } from "@app/lib/client/greetings"; import { useSubmitFunction } from "@app/lib/client/utils"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { useAgentConfigurations, useUserMetadata } from "@app/lib/swr"; import { setUserMetadataFromClient } from "@app/lib/user"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ user: UserType; isBuilder: boolean; subscription: SubscriptionType; owner: WorkspaceType; helper: LightAgentConfigurationType | null; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const user = auth.user(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/builder/assistants/[aId]/index.tsx b/front/pages/w/[wId]/builder/assistants/[aId]/index.tsx index cc8212bc1f1d..389cd0ba40e4 100644 --- a/front/pages/w/[wId]/builder/assistants/[aId]/index.tsx +++ b/front/pages/w/[wId]/builder/assistants/[aId]/index.tsx @@ -25,12 +25,11 @@ import type { 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 } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "", URL = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; plan: PlanType; @@ -46,12 +45,7 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ agentConfiguration: AgentConfigurationType; flow: BuilderFlow; baseUrl: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const plan = auth.plan(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/builder/assistants/dust.tsx b/front/pages/w/[wId]/builder/assistants/dust.tsx index ec8e175610d1..c569f456ef7f 100644 --- a/front/pages/w/[wId]/builder/assistants/dust.tsx +++ b/front/pages/w/[wId]/builder/assistants/dust.tsx @@ -22,24 +22,18 @@ import AppLayout from "@app/components/sparkle/AppLayout"; import { AppLayoutSimpleCloseTitle } from "@app/components/sparkle/AppLayoutTitle"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { SendNotificationsContext } from "@app/components/sparkle/Notification"; -import { Authenticator } from "@app/lib/auth"; import { CONNECTOR_CONFIGURATIONS } from "@app/lib/connector_providers"; import { getDisplayNameForDataSource } from "@app/lib/data_sources"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { useAgentConfigurations, useDataSources } from "@app/lib/swr"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/builder/assistants/index.tsx b/front/pages/w/[wId]/builder/assistants/index.tsx index 2cafc2684418..bfa99d8f5dfd 100644 --- a/front/pages/w/[wId]/builder/assistants/index.tsx +++ b/front/pages/w/[wId]/builder/assistants/index.tsx @@ -31,24 +31,18 @@ import { EmptyCallToAction } from "@app/components/EmptyCallToAction"; import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { compareAgentsForSort } from "@app/lib/assistant"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { useAgentConfigurations } from "@app/lib/swr"; import { classNames, subFilter } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; tabScope: AgentConfigurationScope; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/builder/assistants/new.tsx b/front/pages/w/[wId]/builder/assistants/new.tsx index 9464ee847bee..314d4aae0b51 100644 --- a/front/pages/w/[wId]/builder/assistants/new.tsx +++ b/front/pages/w/[wId]/builder/assistants/new.tsx @@ -25,12 +25,11 @@ import type { 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 } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "", URL = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; plan: PlanType; @@ -46,12 +45,7 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ agentConfiguration: AgentConfigurationType | null; flow: BuilderFlow; baseUrl: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const plan = auth.plan(); const subscription = auth.subscription(); 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 57e75315ed3f..41392fd7716e 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 @@ -9,25 +9,19 @@ import type { InferGetServerSidePropsType } from "next"; import WebsiteConfiguration from "@app/components/data_source/WebsiteConfiguration"; import { getDataSource, getDataSources } from "@app/lib/api/data_sources"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import logger from "@app/logger/logger"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; dataSources: DataSourceType[]; dataSource: DataSourceType; webCrawlerConfiguration: WebCrawlerConfigurationType; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); 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 e09da098c7c3..af97fa00547c 100644 --- a/front/pages/w/[wId]/builder/data-sources/[name]/index.tsx +++ b/front/pages/w/[wId]/builder/data-sources/[name]/index.tsx @@ -41,13 +41,12 @@ import { AppLayoutSimpleCloseTitle } from "@app/components/sparkle/AppLayoutTitl import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { SendNotificationsContext } from "@app/components/sparkle/Notification"; import { getDataSource } from "@app/lib/api/data_sources"; -import { Authenticator, getSession } from "@app/lib/auth"; import { tableKey } from "@app/lib/client/tables_query"; 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 { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } 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"; @@ -63,7 +62,7 @@ const { NANGO_SLACK_CONNECTOR_ID = "", } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; plan: PlanType; @@ -83,13 +82,7 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ }; githubAppUrl: string; gaTrackingId: string; -}>(async (context) => { - const session = await getSession(context.req, context.res); - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const plan = auth.plan(); const subscription = auth.subscription(); 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 5fe734f44211..7b9e47b25b02 100644 --- a/front/pages/w/[wId]/builder/data-sources/[name]/search.tsx +++ b/front/pages/w/[wId]/builder/data-sources/[name]/search.tsx @@ -13,24 +13,18 @@ import AppLayout from "@app/components/sparkle/AppLayout"; import { AppLayoutSimpleCloseTitle } from "@app/components/sparkle/AppLayoutTitle"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getDataSource } from "@app/lib/api/data_sources"; -import { Authenticator } from "@app/lib/auth"; import { getDisplayNameForDocument } from "@app/lib/data_sources"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { classNames, timeAgoFrom } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; dataSource: DataSourceType; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); 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 f7fee94f508c..186b9682ee44 100644 --- a/front/pages/w/[wId]/builder/data-sources/[name]/settings.tsx +++ b/front/pages/w/[wId]/builder/data-sources/[name]/settings.tsx @@ -16,24 +16,18 @@ import AppLayout from "@app/components/sparkle/AppLayout"; import { AppLayoutSimpleSaveCancelTitle } from "@app/components/sparkle/AppLayoutTitle"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getDataSource } from "@app/lib/api/data_sources"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; dataSource: DataSourceType; fetchConnectorError?: boolean; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); 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 ab0439fb229f..9f2c57d633a8 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 @@ -26,28 +26,22 @@ import { AppLayoutSimpleSaveCancelTitle } from "@app/components/sparkle/AppLayou import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { SendNotificationsContext } from "@app/components/sparkle/Notification"; import { getDataSource } from "@app/lib/api/data_sources"; -import { Authenticator } from "@app/lib/auth"; import { handleFileUploadToText } from "@app/lib/client/handle_file_upload"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { useTable } from "@app/lib/swr"; import { classNames } from "@app/lib/utils"; import type { UpsertTableFromCsvRequestBody } from "@app/pages/api/w/[wId]/data_sources/[name]/tables/csv"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; dataSource: DataSourceType; loadTableId: string | null; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const plan = auth.plan(); const subscription = auth.subscription(); 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 45111d0298c3..0fec08844808 100644 --- a/front/pages/w/[wId]/builder/data-sources/[name]/upsert.tsx +++ b/front/pages/w/[wId]/builder/data-sources/[name]/upsert.tsx @@ -27,14 +27,13 @@ import { AppLayoutSimpleSaveCancelTitle } from "@app/components/sparkle/AppLayou import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { SendNotificationsContext } from "@app/components/sparkle/Notification"; import { getDataSource } from "@app/lib/api/data_sources"; -import { Authenticator } from "@app/lib/auth"; import { handleFileUploadToText } from "@app/lib/client/handle_file_upload"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; plan: PlanType; @@ -42,12 +41,7 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ dataSource: DataSourceType; loadDocumentId: string | null; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const plan = auth.plan(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/builder/data-sources/managed.tsx b/front/pages/w/[wId]/builder/data-sources/managed.tsx index 5a9a329a4eca..09c573e4c108 100644 --- a/front/pages/w/[wId]/builder/data-sources/managed.tsx +++ b/front/pages/w/[wId]/builder/data-sources/managed.tsx @@ -35,7 +35,7 @@ import { Authenticator } 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 { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { timeAgoFrom } from "@app/lib/utils"; import logger from "@app/logger/logger"; @@ -73,7 +73,7 @@ const REDIRECT_TO_EDIT_PERMISSIONS = [ "intercom", ]; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; @@ -90,12 +90,7 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ intercomConnectorId: string; }; githubAppUrl: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const plan = auth.plan(); const subscription = auth.subscription(); 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 1e53577e2300..e6063dd2f9e4 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 @@ -7,22 +7,16 @@ import type { InferGetServerSidePropsType } from "next"; import WebsiteConfiguration from "@app/components/data_source/WebsiteConfiguration"; import { getDataSources } from "@app/lib/api/data_sources"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; dataSources: DataSourceType[]; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/builder/data-sources/new.tsx b/front/pages/w/[wId]/builder/data-sources/new.tsx index 979419527622..e7e50b609de0 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 } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ 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 d25113c2670a..871255b1551c 100644 --- a/front/pages/w/[wId]/builder/data-sources/public-urls.tsx +++ b/front/pages/w/[wId]/builder/data-sources/public-urls.tsx @@ -24,9 +24,8 @@ import { EmptyCallToAction } from "@app/components/EmptyCallToAction"; import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getDataSources } from "@app/lib/api/data_sources"; -import { Authenticator } from "@app/lib/auth"; import { useSubmitFunction } from "@app/lib/client/utils"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import logger from "@app/logger/logger"; const { GA_TRACKING_ID = "" } = process.env; @@ -35,19 +34,14 @@ type DataSourceWithConnector = DataSourceType & { connector: ConnectorType; }; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; plan: PlanType; readOnly: boolean; dataSources: DataSourceWithConnector[]; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const plan = auth.plan(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/builder/data-sources/static.tsx b/front/pages/w/[wId]/builder/data-sources/static.tsx index 345ba6896d33..02b79aa975d5 100644 --- a/front/pages/w/[wId]/builder/data-sources/static.tsx +++ b/front/pages/w/[wId]/builder/data-sources/static.tsx @@ -18,25 +18,19 @@ import { EmptyCallToAction } from "@app/components/EmptyCallToAction"; import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getDataSources } from "@app/lib/api/data_sources"; -import { Authenticator } from "@app/lib/auth"; import { useSubmitFunction } from "@app/lib/client/utils"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; plan: PlanType; readOnly: boolean; dataSources: DataSourceType[]; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const plan = auth.plan(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/index.tsx b/front/pages/w/[wId]/index.tsx index 7670c6691d2a..074434d79d2c 100644 --- a/front/pages/w/[wId]/index.tsx +++ b/front/pages/w/[wId]/index.tsx @@ -1,28 +1,21 @@ -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; - -export const getServerSideProps = - withDefaultGetServerSidePropsRequirements( - async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - - if (!auth.workspace() || !auth.user()) { - return { - notFound: true, - }; - } +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; +export const getServerSideProps = withDefaultUserAuthRequirements( + async (context, auth) => { + if (!auth.workspace() || !auth.user()) { return { - redirect: { - destination: `/w/${context.query.wId}/assistant/new`, - permanent: false, - }, + notFound: true, }; } - ); + + return { + redirect: { + destination: `/w/${context.query.wId}/assistant/new`, + permanent: false, + }, + }; + } +); export default function Redirect() { return <>; diff --git a/front/pages/w/[wId]/join.tsx b/front/pages/w/[wId]/join.tsx index 3dc5461b55bd..10657528ca1f 100644 --- a/front/pages/w/[wId]/join.tsx +++ b/front/pages/w/[wId]/join.tsx @@ -37,7 +37,7 @@ type OnboardingType = | "domain_invite_link"; export const getServerSideProps = makeGetServerSidePropsRequirementsWrapper({ - requireAuth: false, + requireAuthLevel: "none", })<{ onboardingType: OnboardingType; workspace: LightWorkspaceType; diff --git a/front/pages/w/[wId]/members/index.tsx b/front/pages/w/[wId]/members/index.tsx index 83a7bd635366..c4e85a576bca 100644 --- a/front/pages/w/[wId]/members/index.tsx +++ b/front/pages/w/[wId]/members/index.tsx @@ -40,8 +40,7 @@ import { checkWorkspaceSeatAvailabilityUsingAuth, getWorkspaceVerifiedDomain, } from "@app/lib/api/workspace"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } 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"; @@ -50,7 +49,7 @@ const { GA_TRACKING_ID = "" } = process.env; const CLOSING_ANIMATION_DURATION = 200; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ user: UserType; owner: WorkspaceType; subscription: SubscriptionType; @@ -59,11 +58,7 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ gaTrackingId: string; workspaceHasAvailableSeats: boolean; workspaceVerifiedDomain: WorkspaceDomain | null; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); +}>(async (context, auth) => { const plan = auth.plan(); const owner = auth.workspace(); const user = auth.user(); diff --git a/front/pages/w/[wId]/subscription/index.tsx b/front/pages/w/[wId]/subscription/index.tsx index 81a1263a51bf..18350dfcf751 100644 --- a/front/pages/w/[wId]/subscription/index.tsx +++ b/front/pages/w/[wId]/subscription/index.tsx @@ -18,9 +18,8 @@ import { PricePlans } from "@app/components/PlansTables"; import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationAdmin } from "@app/components/sparkle/navigation"; import { SendNotificationsContext } from "@app/components/sparkle/Notification"; -import { Authenticator } from "@app/lib/auth"; import { useSubmitFunction } from "@app/lib/client/utils"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { FREE_TEST_PLAN_CODE, FREE_UPGRADED_PLAN_CODE, @@ -31,17 +30,12 @@ import { getPlanInvitation } from "@app/lib/plans/subscription"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; planInvitation: PlanInvitationType | null; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); if (!owner || !auth.isAdmin() || !subscription) { diff --git a/front/pages/w/[wId]/subscription/upgrade-enterprise/[secret].tsx b/front/pages/w/[wId]/subscription/upgrade-enterprise/[secret].tsx index 12e53d2c1daa..f974a24e52e6 100644 --- a/front/pages/w/[wId]/subscription/upgrade-enterprise/[secret].tsx +++ b/front/pages/w/[wId]/subscription/upgrade-enterprise/[secret].tsx @@ -1,69 +1,62 @@ -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } 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"; -export const getServerSideProps = - withDefaultGetServerSidePropsRequirements( - async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - - const owner = auth.workspace(); - if (!owner) { - return { - notFound: true, - }; - } - - const token = context.params?.secret as string; - if (!token) { - return { - notFound: true, - }; - } +export const getServerSideProps = withDefaultUserAuthRequirements( + async (context, auth) => { + const owner = auth.workspace(); + if (!owner) { + return { + notFound: true, + }; + } - const invitation = await PlanInvitation.findOne({ - where: { - secret: token, - }, - }); + const token = context.params?.secret as string; + if (!token) { + return { + notFound: true, + }; + } - if (!invitation) { - return { - notFound: true, - }; - } + const invitation = await PlanInvitation.findOne({ + where: { + secret: token, + }, + }); - const targetWorkspace = await Workspace.findOne({ - where: { - id: invitation.workspaceId, - }, - }); - if (!targetWorkspace || targetWorkspace.sId !== owner.sId) { - return { - notFound: true, - }; - } + if (!invitation) { + return { + notFound: true, + }; + } - const { checkoutUrl } = await getCheckoutUrlForUpgrade(auth); - if (!checkoutUrl) { - return { - notFound: true, - }; - } + const targetWorkspace = await Workspace.findOne({ + where: { + id: invitation.workspaceId, + }, + }); + if (!targetWorkspace || targetWorkspace.sId !== owner.sId) { + return { + notFound: true, + }; + } + const { checkoutUrl } = await getCheckoutUrlForUpgrade(auth); + if (!checkoutUrl) { return { - redirect: { - destination: checkoutUrl, - permanent: false, - }, + notFound: true, }; } - ); + + return { + redirect: { + destination: checkoutUrl, + permanent: false, + }, + }; + } +); export default function Redirect() { return <>; 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 857aef8724fb..cccb7677b694 100644 --- a/front/pages/w/[wId]/u/extract/events/[sId]/edit.tsx +++ b/front/pages/w/[wId]/u/extract/events/[sId]/edit.tsx @@ -10,25 +10,19 @@ import React, { useEffect, useRef, useState } from "react"; import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getEventSchema, getExtractedEvent } from "@app/lib/api/extract"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; event: ExtractedEventType; schema: EventSchemaType; readOnly: boolean; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/u/extract/index.tsx b/front/pages/w/[wId]/u/extract/index.tsx index c390c84894cb..1ad14618b56d 100644 --- a/front/pages/w/[wId]/u/extract/index.tsx +++ b/front/pages/w/[wId]/u/extract/index.tsx @@ -8,22 +8,16 @@ import { useRouter } from "next/router"; import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { useEventSchemas } from "@app/lib/swr"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); 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 bda65fb6c1bb..ad7b07cc59c4 100644 --- a/front/pages/w/[wId]/u/extract/templates/[sId]/edit.tsx +++ b/front/pages/w/[wId]/u/extract/templates/[sId]/edit.tsx @@ -7,23 +7,17 @@ import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { ExtractEventSchemaForm } from "@app/components/use/EventSchemaForm"; import { getEventSchema } from "@app/lib/api/extract"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; schema: EventSchemaType; readOnly: boolean; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); 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 2be05bc6452a..4294fb096b73 100644 --- a/front/pages/w/[wId]/u/extract/templates/[sId]/index.tsx +++ b/front/pages/w/[wId]/u/extract/templates/[sId]/index.tsx @@ -24,25 +24,20 @@ import { useSWRConfig } from "swr"; import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getEventSchema } from "@app/lib/api/extract"; -import { Authenticator } from "@app/lib/auth"; import { CONNECTOR_CONFIGURATIONS } from "@app/lib/connector_providers"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { useExtractedEvents } from "@app/lib/swr"; import { classNames, objectToMarkdown } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; schema: EventSchemaType; readOnly: boolean; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/u/extract/templates/new.tsx b/front/pages/w/[wId]/u/extract/templates/new.tsx index 71dbc9aa2784..064bc90eb69e 100644 --- a/front/pages/w/[wId]/u/extract/templates/new.tsx +++ b/front/pages/w/[wId]/u/extract/templates/new.tsx @@ -5,22 +5,16 @@ import type { InferGetServerSidePropsType } from "next"; import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { ExtractEventSchemaForm } from "@app/components/use/EventSchemaForm"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; readOnly: boolean; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/w/[wId]/welcome.tsx b/front/pages/w/[wId]/welcome.tsx index 5eb039cf2f6e..efd9f78e66e2 100644 --- a/front/pages/w/[wId]/welcome.tsx +++ b/front/pages/w/[wId]/welcome.tsx @@ -13,16 +13,15 @@ import { useEffect, useState } from "react"; import OnboardingLayout from "@app/components/sparkle/OnboardingLayout"; import { getUserMetadata } from "@app/lib/api/user"; -import { Authenticator } from "@app/lib/auth"; import { useSubmitFunction } from "@app/lib/client/utils"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } 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 = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ user: UserType; owner: WorkspaceType; isAdmin: boolean; @@ -31,12 +30,7 @@ export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ conversationId: string | null; gaTrackingId: string; baseUrl: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const user = auth.user(); diff --git a/front/pages/w/[wId]/workspace/index.tsx b/front/pages/w/[wId]/workspace/index.tsx index a25e962e0a63..76a84190f14a 100644 --- a/front/pages/w/[wId]/workspace/index.tsx +++ b/front/pages/w/[wId]/workspace/index.tsx @@ -14,22 +14,16 @@ import { useCallback, useEffect, useState } from "react"; import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationAdmin } from "@app/components/sparkle/navigation"; -import { Authenticator } from "@app/lib/auth"; -import { withDefaultGetServerSidePropsRequirements } from "@app/lib/iam/session"; +import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { useWorkspaceAnalytics } from "@app/lib/swr"; const { GA_TRACKING_ID = "" } = process.env; -export const getServerSideProps = withDefaultGetServerSidePropsRequirements<{ +export const getServerSideProps = withDefaultUserAuthRequirements<{ owner: WorkspaceType; subscription: SubscriptionType; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); if (!owner || !auth.isAdmin() || !subscription) { From c12e091cdb603680fcc53a0ea07e1c760f867ece Mon Sep 17 00:00:00 2001 From: Flavien David Date: Fri, 8 Mar 2024 14:50:56 +0100 Subject: [PATCH 3/6] :shirt: --- front/lib/iam/provider.ts | 3 ++- front/pages/poke/[wId]/assistants/[aId]/index.tsx | 2 +- front/pages/poke/[wId]/data_sources/[name]/index.tsx | 2 +- front/pages/poke/[wId]/data_sources/[name]/search.tsx | 2 +- front/pages/poke/[wId]/data_sources/[name]/view.tsx | 2 +- front/pages/poke/[wId]/index.tsx | 2 +- front/pages/poke/[wId]/memberships.tsx | 2 +- front/pages/poke/connectors/[connectorId]/index.tsx | 2 +- front/pages/poke/index.tsx | 2 +- front/pages/poke/plans.tsx | 2 +- front/pages/w/[wId]/builder/data-sources/new.tsx | 8 +------- 11 files changed, 12 insertions(+), 17 deletions(-) diff --git a/front/lib/iam/provider.ts b/front/lib/iam/provider.ts index cf0bac3577de..14fb43669a9d 100644 --- a/front/lib/iam/provider.ts +++ b/front/lib/iam/provider.ts @@ -33,7 +33,8 @@ function isAuth0Session(session: unknown): session is Session { // We only expose generic types to ease phasing out. -export type SessionWithUser = Omit & { user: ExternalUser }; +// Overrides the Auth0 type definition entirely, to only expose what we need. +export type SessionWithUser = { user: ExternalUser }; export function isValidSession( session: Session | null diff --git a/front/pages/poke/[wId]/assistants/[aId]/index.tsx b/front/pages/poke/[wId]/assistants/[aId]/index.tsx index 0756ed2d155e..645d09a4bbdd 100644 --- a/front/pages/poke/[wId]/assistants/[aId]/index.tsx +++ b/front/pages/poke/[wId]/assistants/[aId]/index.tsx @@ -13,7 +13,7 @@ import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; export const getServerSideProps = withSuperUserAuthRequirements<{ agentConfigurations: AgentConfigurationType[]; -}>(async (context, session, auth) => { +}>(async (context, auth) => { if (!auth.isDustSuperUser()) { return { notFound: true, diff --git a/front/pages/poke/[wId]/data_sources/[name]/index.tsx b/front/pages/poke/[wId]/data_sources/[name]/index.tsx index ebc7ddaa4fe3..2919e7581a23 100644 --- a/front/pages/poke/[wId]/data_sources/[name]/index.tsx +++ b/front/pages/poke/[wId]/data_sources/[name]/index.tsx @@ -42,7 +42,7 @@ export const getServerSideProps = withSuperUserAuthRequirements<{ githubCodeSyncEnabled: boolean; }; temporalWorkspace: string; -}>(async (context, session, auth) => { +}>(async (context, auth) => { const owner = auth.workspace(); if (!owner || !auth.isDustSuperUser()) { diff --git a/front/pages/poke/[wId]/data_sources/[name]/search.tsx b/front/pages/poke/[wId]/data_sources/[name]/search.tsx index de3df7024970..9a1e1952c853 100644 --- a/front/pages/poke/[wId]/data_sources/[name]/search.tsx +++ b/front/pages/poke/[wId]/data_sources/[name]/search.tsx @@ -15,7 +15,7 @@ import { classNames, timeAgoFrom } from "@app/lib/utils"; export const getServerSideProps = withSuperUserAuthRequirements<{ owner: WorkspaceType; dataSource: DataSourceType; -}>(async (context, session, auth) => { +}>(async (context, auth) => { const owner = auth.workspace(); if (!owner || !auth.isAdmin()) { diff --git a/front/pages/poke/[wId]/data_sources/[name]/view.tsx b/front/pages/poke/[wId]/data_sources/[name]/view.tsx index 06e750d4ec44..373bbac1d097 100644 --- a/front/pages/poke/[wId]/data_sources/[name]/view.tsx +++ b/front/pages/poke/[wId]/data_sources/[name]/view.tsx @@ -12,7 +12,7 @@ import logger from "@app/logger/logger"; export const getServerSideProps = withSuperUserAuthRequirements<{ document: CoreAPIDocument; -}>(async (context, session, auth) => { +}>(async (context, auth) => { if (!auth.isDustSuperUser()) { return { notFound: true, diff --git a/front/pages/poke/[wId]/index.tsx b/front/pages/poke/[wId]/index.tsx index cb37624c37f3..70ee1b15ae5a 100644 --- a/front/pages/poke/[wId]/index.tsx +++ b/front/pages/poke/[wId]/index.tsx @@ -54,7 +54,7 @@ export const getServerSideProps = withSuperUserAuthRequirements<{ agentConfigurations: AgentConfigurationType[]; whitelistableFeatures: WhitelistableFeature[]; registry: typeof DustProdActionRegistry; -}>(async (context, session, auth) => { +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); diff --git a/front/pages/poke/[wId]/memberships.tsx b/front/pages/poke/[wId]/memberships.tsx index 4c539d44a373..3d13d746b6b2 100644 --- a/front/pages/poke/[wId]/memberships.tsx +++ b/front/pages/poke/[wId]/memberships.tsx @@ -15,7 +15,7 @@ import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; export const getServerSideProps = withSuperUserAuthRequirements<{ owner: WorkspaceType; members: UserTypeWithWorkspaces[]; -}>(async (context, session, auth) => { +}>(async (context, auth) => { const owner = auth.workspace(); if (!owner || !auth.isDustSuperUser()) { diff --git a/front/pages/poke/connectors/[connectorId]/index.tsx b/front/pages/poke/connectors/[connectorId]/index.tsx index 8f3ca38afacf..b47f938896a7 100644 --- a/front/pages/poke/connectors/[connectorId]/index.tsx +++ b/front/pages/poke/connectors/[connectorId]/index.tsx @@ -5,7 +5,7 @@ import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; import logger from "@app/logger/logger"; export const getServerSideProps = withSuperUserAuthRequirements( - async (context, session, auth) => { + async (context, auth) => { if (!auth.isDustSuperUser()) { return { notFound: true, diff --git a/front/pages/poke/index.tsx b/front/pages/poke/index.tsx index 0e0ac7503f69..d947439dcdac 100644 --- a/front/pages/poke/index.tsx +++ b/front/pages/poke/index.tsx @@ -8,7 +8,7 @@ import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; import { usePokeWorkspaces } from "@app/lib/swr"; export const getServerSideProps = withSuperUserAuthRequirements( - async (context, session, auth) => { + async (context, auth) => { if (!auth.isDustSuperUser()) { return { notFound: true, diff --git a/front/pages/poke/plans.tsx b/front/pages/poke/plans.tsx index cd0a511b5848..48e32c20c23e 100644 --- a/front/pages/poke/plans.tsx +++ b/front/pages/poke/plans.tsx @@ -26,7 +26,7 @@ import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; import { usePokePlans } from "@app/lib/swr"; export const getServerSideProps = withSuperUserAuthRequirements( - async (context, session, auth) => { + async (context, auth) => { if (!auth.isDustSuperUser()) { return { notFound: true, diff --git a/front/pages/w/[wId]/builder/data-sources/new.tsx b/front/pages/w/[wId]/builder/data-sources/new.tsx index e7e50b609de0..e2e094450eb4 100644 --- a/front/pages/w/[wId]/builder/data-sources/new.tsx +++ b/front/pages/w/[wId]/builder/data-sources/new.tsx @@ -11,7 +11,6 @@ import AppLayout from "@app/components/sparkle/AppLayout"; import { AppLayoutSimpleSaveCancelTitle } from "@app/components/sparkle/AppLayoutTitle"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { getDataSources } from "@app/lib/api/data_sources"; -import { Authenticator } from "@app/lib/auth"; import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; @@ -22,12 +21,7 @@ export const getServerSideProps = withDefaultUserAuthRequirements<{ subscription: SubscriptionType; dataSources: DataSourceType[]; gaTrackingId: string; -}>(async (context, session) => { - const auth = await Authenticator.fromSession( - session, - context.params?.wId as string - ); - +}>(async (context, auth) => { const owner = auth.workspace(); const subscription = auth.subscription(); From 0838e0cef134a0b5f992fb71b7dd841b34ec1b2e Mon Sep 17 00:00:00 2001 From: Flavien David Date: Fri, 8 Mar 2024 14:57:32 +0100 Subject: [PATCH 4/6] :sparkles: --- front/lib/iam/session.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/front/lib/iam/session.ts b/front/lib/iam/session.ts index c16e3feb3a17..de04ee92855a 100644 --- a/front/lib/iam/session.ts +++ b/front/lib/iam/session.ts @@ -113,16 +113,13 @@ async function getAuthenticator( } const { wId } = context.params ?? {}; - if (typeof wId !== "string") { - return null; - } switch (requireAuthLevel) { case "user": - return Authenticator.fromSession(session, wId); + return Authenticator.fromSession(session, wId as string); case "superuser": - return Authenticator.fromSuperUserSession(session, wId); + return Authenticator.fromSuperUserSession(session, wId as string); default: return null; @@ -151,7 +148,6 @@ export function makeGetServerSidePropsRequirementsWrapper< requireAuthLevel !== "none" && (!session || !isValidSession(session)) ) { - // TODO: Check if the user has a workspace. return { redirect: { permanent: false, From 8387d8426b7b4c871f060e72d90ef252982967da Mon Sep 17 00:00:00 2001 From: Flavien David Date: Fri, 8 Mar 2024 15:12:22 +0100 Subject: [PATCH 5/6] :sparkles: --- front/lib/iam/session.ts | 11 +++++++---- front/pages/poke/[wId]/data_sources/[name]/view.tsx | 1 - front/pages/w/[wId]/builder/data-sources/managed.tsx | 1 - 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/front/lib/iam/session.ts b/front/lib/iam/session.ts index de04ee92855a..5bc97dc7850d 100644 --- a/front/lib/iam/session.ts +++ b/front/lib/iam/session.ts @@ -83,6 +83,8 @@ export async function getUserFromSession( }; } +export type AuthLevel = "none" | "user" | "superuser"; + interface MakeGetServerSidePropsRequirementsWrapperOptions< R extends AuthLevel = "user" > { @@ -101,8 +103,6 @@ export type CustomGetServerSideProps< session: RequireAuthLevel extends "none" ? null : SessionWithUser ) => Promise>; -export type AuthLevel = "none" | "user" | "superuser"; - async function getAuthenticator( context: GetServerSidePropsContext, session: SessionWithUser | null, @@ -113,13 +113,16 @@ async function getAuthenticator( } const { wId } = context.params ?? {}; + const workspaceId = typeof wId === "string" ? wId : null; switch (requireAuthLevel) { case "user": - return Authenticator.fromSession(session, wId as string); + return workspaceId + ? Authenticator.fromSession(session, workspaceId) + : null; case "superuser": - return Authenticator.fromSuperUserSession(session, wId as string); + return Authenticator.fromSuperUserSession(session, workspaceId); default: return null; diff --git a/front/pages/poke/[wId]/data_sources/[name]/view.tsx b/front/pages/poke/[wId]/data_sources/[name]/view.tsx index 373bbac1d097..9b8f9685a295 100644 --- a/front/pages/poke/[wId]/data_sources/[name]/view.tsx +++ b/front/pages/poke/[wId]/data_sources/[name]/view.tsx @@ -5,7 +5,6 @@ import type { InferGetServerSidePropsType } from "next"; import PokeNavbar from "@app/components/poke/PokeNavbar"; import { getDataSource } from "@app/lib/api/data_sources"; -import { Authenticator } from "@app/lib/auth"; import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; import { classNames } from "@app/lib/utils"; import logger from "@app/logger/logger"; diff --git a/front/pages/w/[wId]/builder/data-sources/managed.tsx b/front/pages/w/[wId]/builder/data-sources/managed.tsx index 09c573e4c108..5683ece2a07c 100644 --- a/front/pages/w/[wId]/builder/data-sources/managed.tsx +++ b/front/pages/w/[wId]/builder/data-sources/managed.tsx @@ -31,7 +31,6 @@ import AppLayout from "@app/components/sparkle/AppLayout"; import { subNavigationBuild } from "@app/components/sparkle/navigation"; import { SendNotificationsContext } from "@app/components/sparkle/Notification"; import { getDataSources } from "@app/lib/api/data_sources"; -import { Authenticator } 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"; From a52c05cc8b98cc6059cc3faf225f91ba71303cf0 Mon Sep 17 00:00:00 2001 From: Flavien David Date: Fri, 8 Mar 2024 16:18:40 +0100 Subject: [PATCH 6/6] s/AuthLevel/UserPrivilege --- front/lib/iam/session.ts | 49 ++++++++++++++++----------- front/logger/withlogging.ts | 16 ++++++--- front/pages/index.tsx | 2 +- front/pages/login-error.tsx | 2 +- front/pages/sso-enforced.tsx | 64 ++++++++++++++++++++++++++++++++++++ front/pages/w/[wId]/join.tsx | 2 +- 6 files changed, 109 insertions(+), 26 deletions(-) create mode 100644 front/pages/sso-enforced.tsx diff --git a/front/lib/iam/session.ts b/front/lib/iam/session.ts index 5bc97dc7850d..c1ed9c901122 100644 --- a/front/lib/iam/session.ts +++ b/front/lib/iam/session.ts @@ -83,30 +83,30 @@ export async function getUserFromSession( }; } -export type AuthLevel = "none" | "user" | "superuser"; +export type UserPrivilege = "none" | "user" | "superuser"; interface MakeGetServerSidePropsRequirementsWrapperOptions< - R extends AuthLevel = "user" + R extends UserPrivilege = "user" > { enableLogging?: boolean; - requireAuthLevel: R; + requireUserPrivilege: R; } export type CustomGetServerSideProps< Props extends { [key: string]: any } = { [key: string]: any }, Params extends ParsedUrlQuery = ParsedUrlQuery, Preview extends PreviewData = PreviewData, - RequireAuthLevel extends AuthLevel = "user" + RequireUserPrivilege extends UserPrivilege = "user" > = ( context: GetServerSidePropsContext, - auth: RequireAuthLevel extends "none" ? null : Authenticator, - session: RequireAuthLevel extends "none" ? null : SessionWithUser + auth: RequireUserPrivilege extends "none" ? null : Authenticator, + session: RequireUserPrivilege extends "none" ? null : SessionWithUser ) => Promise>; async function getAuthenticator( context: GetServerSidePropsContext, session: SessionWithUser | null, - requireAuthLevel: AuthLevel + requireUserPrivilege: UserPrivilege ) { if (!session) { return null; @@ -115,7 +115,7 @@ async function getAuthenticator( const { wId } = context.params ?? {}; const workspaceId = typeof wId === "string" ? wId : null; - switch (requireAuthLevel) { + switch (requireUserPrivilege) { case "user": return workspaceId ? Authenticator.fromSession(session, workspaceId) @@ -130,25 +130,34 @@ async function getAuthenticator( } export function makeGetServerSidePropsRequirementsWrapper< - RequireAuthLevel extends AuthLevel = "user" + RequireUserPrivilege extends UserPrivilege = "user" >({ enableLogging = true, - requireAuthLevel, -}: MakeGetServerSidePropsRequirementsWrapperOptions) { + requireUserPrivilege, +}: MakeGetServerSidePropsRequirementsWrapperOptions) { return ( - getServerSideProps: CustomGetServerSideProps + getServerSideProps: CustomGetServerSideProps< + T, + any, + any, + RequireUserPrivilege + > ) => { return async ( context: GetServerSidePropsContext ) => { const session = - requireAuthLevel !== "none" + requireUserPrivilege !== "none" ? await getSession(context.req, context.res) : null; - const auth = await getAuthenticator(context, session, requireAuthLevel); + const auth = await getAuthenticator( + context, + session, + requireUserPrivilege + ); if ( - requireAuthLevel !== "none" && + requireUserPrivilege !== "none" && (!session || !isValidSession(session)) ) { return { @@ -160,10 +169,10 @@ export function makeGetServerSidePropsRequirementsWrapper< }; } - const userSession = session as RequireAuthLevel extends "none" + const userSession = session as RequireUserPrivilege extends "none" ? null : SessionWithUser; - const userAuth = auth as RequireAuthLevel extends "none" + const userAuth = auth as RequireUserPrivilege extends "none" ? null : Authenticator; @@ -181,7 +190,9 @@ export function makeGetServerSidePropsRequirementsWrapper< } export const withDefaultUserAuthRequirements = - makeGetServerSidePropsRequirementsWrapper({ requireAuthLevel: "user" }); + makeGetServerSidePropsRequirementsWrapper({ requireUserPrivilege: "user" }); export const withSuperUserAuthRequirements = - makeGetServerSidePropsRequirementsWrapper({ requireAuthLevel: "superuser" }); + makeGetServerSidePropsRequirementsWrapper({ + requireUserPrivilege: "superuser", + }); diff --git a/front/logger/withlogging.ts b/front/logger/withlogging.ts index f456dfa953d5..69431805f67d 100644 --- a/front/logger/withlogging.ts +++ b/front/logger/withlogging.ts @@ -6,7 +6,10 @@ import tracer from "dd-trace"; import StatsD from "hot-shots"; import type { NextApiRequest, NextApiResponse } from "next"; -import type { AuthLevel, CustomGetServerSideProps } from "@app/lib/iam/session"; +import type { + CustomGetServerSideProps, + UserPrivilege, +} from "@app/lib/iam/session"; import logger from "./logger"; @@ -145,10 +148,15 @@ export function apiError( export function withGetServerSidePropsLogging< T extends { [key: string]: any }, - RequireAuthLevel extends AuthLevel = "user" + RequireUserPrivilege extends UserPrivilege = "user" >( - getServerSideProps: CustomGetServerSideProps -): CustomGetServerSideProps { + getServerSideProps: CustomGetServerSideProps< + T, + any, + any, + RequireUserPrivilege + > +): CustomGetServerSideProps { return async (context, auth, session) => { const now = new Date(); diff --git a/front/pages/index.tsx b/front/pages/index.tsx index d43a0fdf7a0f..2e0fa9f05a42 100644 --- a/front/pages/index.tsx +++ b/front/pages/index.tsx @@ -55,7 +55,7 @@ import { classNames } from "@app/lib/utils"; const { GA_TRACKING_ID = "" } = process.env; export const getServerSideProps = makeGetServerSidePropsRequirementsWrapper({ - requireAuthLevel: "none", + requireUserPrivilege: "none", })<{ gaTrackingId: string; }>(async (context) => { diff --git a/front/pages/login-error.tsx b/front/pages/login-error.tsx index 723734869350..5849d49223c3 100644 --- a/front/pages/login-error.tsx +++ b/front/pages/login-error.tsx @@ -7,7 +7,7 @@ import { makeGetServerSidePropsRequirementsWrapper } from "@app/lib/iam/session" const { GA_TRACKING_ID = "" } = process.env; export const getServerSideProps = makeGetServerSidePropsRequirementsWrapper({ - requireAuthLevel: "none", + requireUserPrivilege: "none", })<{ domain: string | null; gaTrackingId: string; diff --git a/front/pages/sso-enforced.tsx b/front/pages/sso-enforced.tsx new file mode 100644 index 000000000000..ff7a78a1b336 --- /dev/null +++ b/front/pages/sso-enforced.tsx @@ -0,0 +1,64 @@ +import { Button, Logo } from "@dust-tt/sparkle"; +import type { InferGetServerSidePropsType } from "next"; +import Link from "next/link"; + +import { makeEnterpriseConnectionInitiateLoginUrl } from "@app/lib/api/enterprise_connection"; +import { makeGetServerSidePropsRequirementsWrapper } from "@app/lib/iam/session"; + +export const getServerSideProps = makeGetServerSidePropsRequirementsWrapper({ + requireUserPrivilege: "none", +})<{ + initiatedLoginUrl: string; +}>(async (context) => { + const workspaceId = (context.query.workspaceId as string) ?? null; + + if (!workspaceId) { + return { + notFound: true, + }; + } + + return { + props: { + initiatedLoginUrl: makeEnterpriseConnectionInitiateLoginUrl(workspaceId), + }, + }; +}); + +export default function SsoEnforced({ + initiatedLoginUrl, +}: InferGetServerSidePropsType) { + return ( + <> +
+
+
+
+
+
+ +
+

+ + Secure AI assistant + {" "} +
+ with your company’s knowledge +
+

+
+
+
+

+ Access requires Single Sign-On (SSO) authentication. Use your SSO + provider to sign in.{" "} +

+ +
+
+
+ + ); +} diff --git a/front/pages/w/[wId]/join.tsx b/front/pages/w/[wId]/join.tsx index 10657528ca1f..9974831c5cbf 100644 --- a/front/pages/w/[wId]/join.tsx +++ b/front/pages/w/[wId]/join.tsx @@ -37,7 +37,7 @@ type OnboardingType = | "domain_invite_link"; export const getServerSideProps = makeGetServerSidePropsRequirementsWrapper({ - requireAuthLevel: "none", + requireUserPrivilege: "none", })<{ onboardingType: OnboardingType; workspace: LightWorkspaceType;