feat(): enable custom domain usage (#9911)
# Content - Introduce the `workspaceUrls` property. It contains two sub-properties: `customUrl, subdomainUrl`. These endpoints are used to access the workspace. Even if the `workspaceUrls` is invalid for multiple reasons, the `subdomainUrl` remains valid. - Introduce `ResolveField` workspaceEndpoints to avoid unnecessary URL computation on the frontend part. - Add a `forceSubdomainUrl` to avoid custom URL using a query parameter
This commit is contained in:
@ -81,7 +81,6 @@ module.exports = {
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/interface-name-prefix': 'off',
|
||||
'@typescript-eslint/no-empty-function': 'off',
|
||||
'@typescript-eslint/no-empty-interface': [
|
||||
'error',
|
||||
{
|
||||
|
||||
@ -18,7 +18,7 @@ module.exports = {
|
||||
},
|
||||
config: {
|
||||
namingConvention: { enumValues: 'keep' },
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@ -113,7 +113,7 @@ export type AvailableWorkspaceOutput = {
|
||||
id: Scalars['String']['output'];
|
||||
logo?: Maybe<Scalars['String']['output']>;
|
||||
sso: Array<SsoConnection>;
|
||||
subdomain: Scalars['String']['output'];
|
||||
workspaceUrls: WorkspaceUrls;
|
||||
};
|
||||
|
||||
export type Billing = {
|
||||
@ -475,19 +475,11 @@ export type EnvironmentVariable = {
|
||||
};
|
||||
|
||||
export enum EnvironmentVariablesGroup {
|
||||
Analytics = 'Analytics',
|
||||
Authentication = 'Authentication',
|
||||
Billing = 'Billing',
|
||||
Cache = 'Cache',
|
||||
Database = 'Database',
|
||||
Email = 'Email',
|
||||
Frontend = 'Frontend',
|
||||
Logging = 'Logging',
|
||||
Other = 'Other',
|
||||
QueueConfig = 'QueueConfig',
|
||||
ServerConfig = 'ServerConfig',
|
||||
Storage = 'Storage',
|
||||
Support = 'Support',
|
||||
Workspace = 'Workspace'
|
||||
}
|
||||
|
||||
@ -706,7 +698,7 @@ export enum IdentityProviderType {
|
||||
export type ImpersonateOutput = {
|
||||
__typename?: 'ImpersonateOutput';
|
||||
loginToken: AuthToken;
|
||||
workspace: WorkspaceSubdomainAndId;
|
||||
workspace: WorkspaceUrlsAndId;
|
||||
};
|
||||
|
||||
export type Index = {
|
||||
@ -1360,10 +1352,9 @@ export type PublicWorkspaceDataOutput = {
|
||||
__typename?: 'PublicWorkspaceDataOutput';
|
||||
authProviders: AuthProviders;
|
||||
displayName?: Maybe<Scalars['String']['output']>;
|
||||
hostname?: Maybe<Scalars['String']['output']>;
|
||||
id: Scalars['String']['output'];
|
||||
logo?: Maybe<Scalars['String']['output']>;
|
||||
subdomain: Scalars['String']['output'];
|
||||
workspaceUrls: WorkspaceUrls;
|
||||
};
|
||||
|
||||
export type PublishServerlessFunctionInput = {
|
||||
@ -1394,7 +1385,7 @@ export type Query = {
|
||||
getHostnameDetails?: Maybe<CustomHostnameDetails>;
|
||||
getPostgresCredentials?: Maybe<PostgresCredentials>;
|
||||
getProductPrices: BillingProductPricesOutput;
|
||||
getPublicWorkspaceDataBySubdomain: PublicWorkspaceDataOutput;
|
||||
getPublicWorkspaceDataByDomain: PublicWorkspaceDataOutput;
|
||||
getRoles: Array<Role>;
|
||||
getServerlessFunctionSourceCode?: Maybe<Scalars['JSON']['output']>;
|
||||
getTimelineCalendarEventsFromCompanyId: TimelineCalendarEventsWithTotal;
|
||||
@ -1792,7 +1783,7 @@ export type SetupSsoOutput = {
|
||||
export type SignUpOutput = {
|
||||
__typename?: 'SignUpOutput';
|
||||
loginToken: AuthToken;
|
||||
workspace: WorkspaceSubdomainAndId;
|
||||
workspace: WorkspaceUrlsAndId;
|
||||
};
|
||||
|
||||
export enum SubscriptionInterval {
|
||||
@ -1994,7 +1985,7 @@ export type User = {
|
||||
analyticsTinybirdJwts?: Maybe<AnalyticsTinybirdJwtMap>;
|
||||
canImpersonate: Scalars['Boolean']['output'];
|
||||
createdAt: Scalars['DateTime']['output'];
|
||||
currentWorkspace?: Maybe<Workspace>;
|
||||
currentWorkspace: Workspace;
|
||||
defaultAvatarUrl?: Maybe<Scalars['String']['output']>;
|
||||
deletedAt?: Maybe<Scalars['DateTime']['output']>;
|
||||
disabled?: Maybe<Scalars['Boolean']['output']>;
|
||||
@ -2126,6 +2117,7 @@ export type Workspace = {
|
||||
subdomain: Scalars['String']['output'];
|
||||
updatedAt: Scalars['DateTime']['output'];
|
||||
workspaceMembersCount?: Maybe<Scalars['Float']['output']>;
|
||||
workspaceUrls: WorkspaceUrls;
|
||||
};
|
||||
|
||||
export enum WorkspaceActivationStatus {
|
||||
@ -2202,10 +2194,16 @@ export type WorkspaceNameAndId = {
|
||||
id: Scalars['String']['output'];
|
||||
};
|
||||
|
||||
export type WorkspaceSubdomainAndId = {
|
||||
__typename?: 'WorkspaceSubdomainAndId';
|
||||
export type WorkspaceUrls = {
|
||||
__typename?: 'workspaceUrls';
|
||||
customUrl?: Maybe<Scalars['String']['output']>;
|
||||
subdomainUrl: Scalars['String']['output'];
|
||||
};
|
||||
|
||||
export type WorkspaceUrlsAndId = {
|
||||
__typename?: 'workspaceUrlsAndId';
|
||||
id: Scalars['String']['output'];
|
||||
subdomain: Scalars['String']['output'];
|
||||
workspaceUrls: WorkspaceUrls;
|
||||
};
|
||||
|
||||
export type RemoteServerFieldsFragment = { __typename?: 'RemoteServer', id: string, createdAt: any, foreignDataWrapperId: string, foreignDataWrapperOptions?: any | null, foreignDataWrapperType: string, updatedAt: any, schema?: string | null, label: string, userMappingOptions?: { __typename?: 'UserMappingOptionsUser', user?: string | null } | null };
|
||||
|
||||
@ -106,7 +106,7 @@ export type AvailableWorkspaceOutput = {
|
||||
id: Scalars['String'];
|
||||
logo?: Maybe<Scalars['String']>;
|
||||
sso: Array<SsoConnection>;
|
||||
subdomain: Scalars['String'];
|
||||
workspaceUrls: WorkspaceUrls;
|
||||
};
|
||||
|
||||
export type Billing = {
|
||||
@ -407,19 +407,11 @@ export type EnvironmentVariable = {
|
||||
};
|
||||
|
||||
export enum EnvironmentVariablesGroup {
|
||||
Analytics = 'Analytics',
|
||||
Authentication = 'Authentication',
|
||||
Billing = 'Billing',
|
||||
Cache = 'Cache',
|
||||
Database = 'Database',
|
||||
Email = 'Email',
|
||||
Frontend = 'Frontend',
|
||||
Logging = 'Logging',
|
||||
Other = 'Other',
|
||||
QueueConfig = 'QueueConfig',
|
||||
ServerConfig = 'ServerConfig',
|
||||
Storage = 'Storage',
|
||||
Support = 'Support',
|
||||
Workspace = 'Workspace'
|
||||
}
|
||||
|
||||
@ -631,7 +623,7 @@ export enum IdentityProviderType {
|
||||
export type ImpersonateOutput = {
|
||||
__typename?: 'ImpersonateOutput';
|
||||
loginToken: AuthToken;
|
||||
workspace: WorkspaceSubdomainAndId;
|
||||
workspace: WorkspaceUrlsAndId;
|
||||
};
|
||||
|
||||
export type Index = {
|
||||
@ -1227,10 +1219,9 @@ export type PublicWorkspaceDataOutput = {
|
||||
__typename?: 'PublicWorkspaceDataOutput';
|
||||
authProviders: AuthProviders;
|
||||
displayName?: Maybe<Scalars['String']>;
|
||||
hostname?: Maybe<Scalars['String']>;
|
||||
id: Scalars['String'];
|
||||
logo?: Maybe<Scalars['String']>;
|
||||
subdomain: Scalars['String'];
|
||||
workspaceUrls: WorkspaceUrls;
|
||||
};
|
||||
|
||||
export type PublishServerlessFunctionInput = {
|
||||
@ -1258,7 +1249,7 @@ export type Query = {
|
||||
getHostnameDetails?: Maybe<CustomHostnameDetails>;
|
||||
getPostgresCredentials?: Maybe<PostgresCredentials>;
|
||||
getProductPrices: BillingProductPricesOutput;
|
||||
getPublicWorkspaceDataBySubdomain: PublicWorkspaceDataOutput;
|
||||
getPublicWorkspaceDataByDomain: PublicWorkspaceDataOutput;
|
||||
getRoles: Array<Role>;
|
||||
getServerlessFunctionSourceCode?: Maybe<Scalars['JSON']>;
|
||||
getTimelineCalendarEventsFromCompanyId: TimelineCalendarEventsWithTotal;
|
||||
@ -1588,7 +1579,7 @@ export type SetupSsoOutput = {
|
||||
export type SignUpOutput = {
|
||||
__typename?: 'SignUpOutput';
|
||||
loginToken: AuthToken;
|
||||
workspace: WorkspaceSubdomainAndId;
|
||||
workspace: WorkspaceUrlsAndId;
|
||||
};
|
||||
|
||||
export enum SubscriptionInterval {
|
||||
@ -1782,7 +1773,7 @@ export type User = {
|
||||
analyticsTinybirdJwts?: Maybe<AnalyticsTinybirdJwtMap>;
|
||||
canImpersonate: Scalars['Boolean'];
|
||||
createdAt: Scalars['DateTime'];
|
||||
currentWorkspace?: Maybe<Workspace>;
|
||||
currentWorkspace: Workspace;
|
||||
defaultAvatarUrl?: Maybe<Scalars['String']>;
|
||||
deletedAt?: Maybe<Scalars['DateTime']>;
|
||||
disabled?: Maybe<Scalars['Boolean']>;
|
||||
@ -1904,6 +1895,7 @@ export type Workspace = {
|
||||
subdomain: Scalars['String'];
|
||||
updatedAt: Scalars['DateTime'];
|
||||
workspaceMembersCount?: Maybe<Scalars['Float']>;
|
||||
workspaceUrls: WorkspaceUrls;
|
||||
};
|
||||
|
||||
export enum WorkspaceActivationStatus {
|
||||
@ -1980,10 +1972,16 @@ export type WorkspaceNameAndId = {
|
||||
id: Scalars['String'];
|
||||
};
|
||||
|
||||
export type WorkspaceSubdomainAndId = {
|
||||
__typename?: 'WorkspaceSubdomainAndId';
|
||||
export type WorkspaceUrls = {
|
||||
__typename?: 'workspaceUrls';
|
||||
customUrl?: Maybe<Scalars['String']>;
|
||||
subdomainUrl: Scalars['String'];
|
||||
};
|
||||
|
||||
export type WorkspaceUrlsAndId = {
|
||||
__typename?: 'workspaceUrlsAndId';
|
||||
id: Scalars['String'];
|
||||
subdomain: Scalars['String'];
|
||||
workspaceUrls: WorkspaceUrls;
|
||||
};
|
||||
|
||||
export type TimelineCalendarEventFragmentFragment = { __typename?: 'TimelineCalendarEvent', id: any, title: string, description: string, location: string, startsAt: string, endsAt: string, isFullDay: boolean, visibility: CalendarChannelVisibility, participants: Array<{ __typename?: 'TimelineCalendarEventParticipant', personId?: any | null, workspaceMemberId?: any | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }> };
|
||||
@ -2130,7 +2128,7 @@ export type ImpersonateMutationVariables = Exact<{
|
||||
}>;
|
||||
|
||||
|
||||
export type ImpersonateMutation = { __typename?: 'Mutation', impersonate: { __typename?: 'ImpersonateOutput', workspace: { __typename?: 'WorkspaceSubdomainAndId', subdomain: string, id: string }, loginToken: { __typename?: 'AuthToken', token: string, expiresAt: string } } };
|
||||
export type ImpersonateMutation = { __typename?: 'Mutation', impersonate: { __typename?: 'ImpersonateOutput', workspace: { __typename?: 'workspaceUrlsAndId', id: string, workspaceUrls: { __typename?: 'workspaceUrls', subdomainUrl: string, customUrl?: string | null } }, loginToken: { __typename?: 'AuthToken', token: string, expiresAt: string } } };
|
||||
|
||||
export type RenewTokenMutationVariables = Exact<{
|
||||
appToken: Scalars['String'];
|
||||
@ -2156,7 +2154,7 @@ export type SignUpMutationVariables = Exact<{
|
||||
}>;
|
||||
|
||||
|
||||
export type SignUpMutation = { __typename?: 'Mutation', signUp: { __typename?: 'SignUpOutput', loginToken: { __typename?: 'AuthToken', token: string, expiresAt: string }, workspace: { __typename?: 'WorkspaceSubdomainAndId', id: string, subdomain: string } } };
|
||||
export type SignUpMutation = { __typename?: 'Mutation', signUp: { __typename?: 'SignUpOutput', loginToken: { __typename?: 'AuthToken', token: string, expiresAt: string }, workspace: { __typename?: 'workspaceUrlsAndId', id: string, workspaceUrls: { __typename?: 'workspaceUrls', subdomainUrl: string, customUrl?: string | null } } } };
|
||||
|
||||
export type UpdatePasswordViaResetTokenMutationVariables = Exact<{
|
||||
token: Scalars['String'];
|
||||
@ -2172,12 +2170,12 @@ export type CheckUserExistsQueryVariables = Exact<{
|
||||
}>;
|
||||
|
||||
|
||||
export type CheckUserExistsQuery = { __typename?: 'Query', checkUserExists: { __typename: 'UserExists', exists: boolean, isEmailVerified: boolean, availableWorkspaces: Array<{ __typename?: 'AvailableWorkspaceOutput', id: string, displayName?: string | null, subdomain: string, hostname?: string | null, logo?: string | null, sso: Array<{ __typename?: 'SSOConnection', type: IdentityProviderType, id: string, issuer: string, name: string, status: SsoIdentityProviderStatus }> }> } | { __typename: 'UserNotExists', exists: boolean } };
|
||||
export type CheckUserExistsQuery = { __typename?: 'Query', checkUserExists: { __typename: 'UserExists', exists: boolean, isEmailVerified: boolean, availableWorkspaces: Array<{ __typename?: 'AvailableWorkspaceOutput', id: string, displayName?: string | null, logo?: string | null, workspaceUrls: { __typename?: 'workspaceUrls', subdomainUrl: string, customUrl?: string | null }, sso: Array<{ __typename?: 'SSOConnection', type: IdentityProviderType, id: string, issuer: string, name: string, status: SsoIdentityProviderStatus }> }> } | { __typename: 'UserNotExists', exists: boolean } };
|
||||
|
||||
export type GetPublicWorkspaceDataBySubdomainQueryVariables = Exact<{ [key: string]: never; }>;
|
||||
export type GetPublicWorkspaceDataByDomainQueryVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type GetPublicWorkspaceDataBySubdomainQuery = { __typename?: 'Query', getPublicWorkspaceDataBySubdomain: { __typename?: 'PublicWorkspaceDataOutput', id: string, logo?: string | null, displayName?: string | null, subdomain: string, hostname?: string | null, authProviders: { __typename?: 'AuthProviders', google: boolean, magicLink: boolean, password: boolean, microsoft: boolean, sso: Array<{ __typename?: 'SSOIdentityProvider', id: string, name: string, type: IdentityProviderType, status: SsoIdentityProviderStatus, issuer: string }> } } };
|
||||
export type GetPublicWorkspaceDataByDomainQuery = { __typename?: 'Query', getPublicWorkspaceDataByDomain: { __typename?: 'PublicWorkspaceDataOutput', id: string, logo?: string | null, displayName?: string | null, workspaceUrls: { __typename?: 'workspaceUrls', subdomainUrl: string, customUrl?: string | null }, authProviders: { __typename?: 'AuthProviders', google: boolean, magicLink: boolean, password: boolean, microsoft: boolean, sso: Array<{ __typename?: 'SSOIdentityProvider', id: string, name: string, type: IdentityProviderType, status: SsoIdentityProviderStatus, issuer: string }> } } };
|
||||
|
||||
export type ValidatePasswordResetTokenQueryVariables = Exact<{
|
||||
token: Scalars['String'];
|
||||
@ -2291,7 +2289,7 @@ export type ListSsoIdentityProvidersByWorkspaceIdQueryVariables = Exact<{ [key:
|
||||
|
||||
export type ListSsoIdentityProvidersByWorkspaceIdQuery = { __typename?: 'Query', listSSOIdentityProvidersByWorkspaceId: Array<{ __typename?: 'FindAvailableSSOIDPOutput', type: IdentityProviderType, id: string, name: string, issuer: string, status: SsoIdentityProviderStatus }> };
|
||||
|
||||
export type UserQueryFragmentFragment = { __typename?: 'User', id: any, firstName: string, lastName: string, email: string, canImpersonate: boolean, supportUserHash?: string | null, onboardingStatus?: OnboardingStatus | null, userVars: any, analyticsTinybirdJwts?: { __typename?: 'AnalyticsTinybirdJwtMap', getWebhookAnalytics: string, getPageviewsAnalytics: string, getUsersAnalytics: string, getServerlessFunctionDuration: string, getServerlessFunctionSuccessRate: string, getServerlessFunctionErrorCount: string } | null, workspaceMember?: { __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } } | null, workspaceMembers?: Array<{ __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } }> | null, currentWorkspace?: { __typename?: 'Workspace', id: any, displayName?: string | null, logo?: string | null, inviteHash?: string | null, allowImpersonation: boolean, activationStatus: WorkspaceActivationStatus, isPublicInviteLinkEnabled: boolean, isGoogleAuthEnabled: boolean, isMicrosoftAuthEnabled: boolean, isPasswordAuthEnabled: boolean, subdomain: string, hasValidEnterpriseKey: boolean, hostname?: string | null, metadataVersion: number, workspaceMembersCount?: number | null, featureFlags?: Array<{ __typename?: 'FeatureFlag', id: any, key: FeatureFlagKey, value: boolean, workspaceId: string }> | null, currentBillingSubscription?: { __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus, interval?: SubscriptionInterval | null } | null, billingSubscriptions: Array<{ __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus }> } | null, workspaces: Array<{ __typename?: 'UserWorkspace', workspace?: { __typename?: 'Workspace', id: any, logo?: string | null, displayName?: string | null, subdomain: string } | null }> };
|
||||
export type UserQueryFragmentFragment = { __typename?: 'User', id: any, firstName: string, lastName: string, email: string, canImpersonate: boolean, supportUserHash?: string | null, onboardingStatus?: OnboardingStatus | null, userVars: any, analyticsTinybirdJwts?: { __typename?: 'AnalyticsTinybirdJwtMap', getWebhookAnalytics: string, getPageviewsAnalytics: string, getUsersAnalytics: string, getServerlessFunctionDuration: string, getServerlessFunctionSuccessRate: string, getServerlessFunctionErrorCount: string } | null, workspaceMember?: { __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } } | null, workspaceMembers?: Array<{ __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } }> | null, currentWorkspace: { __typename?: 'Workspace', id: any, displayName?: string | null, logo?: string | null, inviteHash?: string | null, allowImpersonation: boolean, activationStatus: WorkspaceActivationStatus, isPublicInviteLinkEnabled: boolean, isGoogleAuthEnabled: boolean, isMicrosoftAuthEnabled: boolean, isPasswordAuthEnabled: boolean, subdomain: string, hasValidEnterpriseKey: boolean, hostname?: string | null, metadataVersion: number, workspaceMembersCount?: number | null, workspaceUrls: { __typename?: 'workspaceUrls', subdomainUrl: string, customUrl?: string | null }, featureFlags?: Array<{ __typename?: 'FeatureFlag', id: any, key: FeatureFlagKey, value: boolean, workspaceId: string }> | null, currentBillingSubscription?: { __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus, interval?: SubscriptionInterval | null } | null, billingSubscriptions: Array<{ __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus }> }, workspaces: Array<{ __typename?: 'UserWorkspace', workspace?: { __typename?: 'Workspace', id: any, logo?: string | null, displayName?: string | null, subdomain: string, hostname?: string | null, workspaceUrls: { __typename?: 'workspaceUrls', subdomainUrl: string, customUrl?: string | null } } | null }> };
|
||||
|
||||
export type DeleteUserAccountMutationVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
@ -2308,7 +2306,7 @@ export type UploadProfilePictureMutation = { __typename?: 'Mutation', uploadProf
|
||||
export type GetCurrentUserQueryVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type GetCurrentUserQuery = { __typename?: 'Query', currentUser: { __typename?: 'User', id: any, firstName: string, lastName: string, email: string, canImpersonate: boolean, supportUserHash?: string | null, onboardingStatus?: OnboardingStatus | null, userVars: any, analyticsTinybirdJwts?: { __typename?: 'AnalyticsTinybirdJwtMap', getWebhookAnalytics: string, getPageviewsAnalytics: string, getUsersAnalytics: string, getServerlessFunctionDuration: string, getServerlessFunctionSuccessRate: string, getServerlessFunctionErrorCount: string } | null, workspaceMember?: { __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } } | null, workspaceMembers?: Array<{ __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } }> | null, currentWorkspace?: { __typename?: 'Workspace', id: any, displayName?: string | null, logo?: string | null, inviteHash?: string | null, allowImpersonation: boolean, activationStatus: WorkspaceActivationStatus, isPublicInviteLinkEnabled: boolean, isGoogleAuthEnabled: boolean, isMicrosoftAuthEnabled: boolean, isPasswordAuthEnabled: boolean, subdomain: string, hasValidEnterpriseKey: boolean, hostname?: string | null, metadataVersion: number, workspaceMembersCount?: number | null, featureFlags?: Array<{ __typename?: 'FeatureFlag', id: any, key: FeatureFlagKey, value: boolean, workspaceId: string }> | null, currentBillingSubscription?: { __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus, interval?: SubscriptionInterval | null } | null, billingSubscriptions: Array<{ __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus }> } | null, workspaces: Array<{ __typename?: 'UserWorkspace', workspace?: { __typename?: 'Workspace', id: any, logo?: string | null, displayName?: string | null, subdomain: string } | null }> } };
|
||||
export type GetCurrentUserQuery = { __typename?: 'Query', currentUser: { __typename?: 'User', id: any, firstName: string, lastName: string, email: string, canImpersonate: boolean, supportUserHash?: string | null, onboardingStatus?: OnboardingStatus | null, userVars: any, analyticsTinybirdJwts?: { __typename?: 'AnalyticsTinybirdJwtMap', getWebhookAnalytics: string, getPageviewsAnalytics: string, getUsersAnalytics: string, getServerlessFunctionDuration: string, getServerlessFunctionSuccessRate: string, getServerlessFunctionErrorCount: string } | null, workspaceMember?: { __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } } | null, workspaceMembers?: Array<{ __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } }> | null, currentWorkspace: { __typename?: 'Workspace', id: any, displayName?: string | null, logo?: string | null, inviteHash?: string | null, allowImpersonation: boolean, activationStatus: WorkspaceActivationStatus, isPublicInviteLinkEnabled: boolean, isGoogleAuthEnabled: boolean, isMicrosoftAuthEnabled: boolean, isPasswordAuthEnabled: boolean, subdomain: string, hasValidEnterpriseKey: boolean, hostname?: string | null, metadataVersion: number, workspaceMembersCount?: number | null, workspaceUrls: { __typename?: 'workspaceUrls', subdomainUrl: string, customUrl?: string | null }, featureFlags?: Array<{ __typename?: 'FeatureFlag', id: any, key: FeatureFlagKey, value: boolean, workspaceId: string }> | null, currentBillingSubscription?: { __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus, interval?: SubscriptionInterval | null } | null, billingSubscriptions: Array<{ __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus }> }, workspaces: Array<{ __typename?: 'UserWorkspace', workspace?: { __typename?: 'Workspace', id: any, logo?: string | null, displayName?: string | null, subdomain: string, hostname?: string | null, workspaceUrls: { __typename?: 'workspaceUrls', subdomainUrl: string, customUrl?: string | null } } | null }> } };
|
||||
|
||||
export type ActivateWorkflowVersionMutationVariables = Exact<{
|
||||
workflowVersionId: Scalars['String'];
|
||||
@ -2399,7 +2397,7 @@ export type ActivateWorkspaceMutationVariables = Exact<{
|
||||
}>;
|
||||
|
||||
|
||||
export type ActivateWorkspaceMutation = { __typename?: 'Mutation', activateWorkspace: { __typename?: 'Workspace', id: any, subdomain: string } };
|
||||
export type ActivateWorkspaceMutation = { __typename?: 'Mutation', activateWorkspace: { __typename?: 'Workspace', id: any } };
|
||||
|
||||
export type DeleteCurrentWorkspaceMutationVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
@ -2430,7 +2428,7 @@ export type GetWorkspaceFromInviteHashQueryVariables = Exact<{
|
||||
}>;
|
||||
|
||||
|
||||
export type GetWorkspaceFromInviteHashQuery = { __typename?: 'Query', findWorkspaceFromInviteHash: { __typename?: 'Workspace', id: any, displayName?: string | null, logo?: string | null, allowImpersonation: boolean, subdomain: string } };
|
||||
export type GetWorkspaceFromInviteHashQuery = { __typename?: 'Query', findWorkspaceFromInviteHash: { __typename?: 'Workspace', id: any, displayName?: string | null, logo?: string | null, allowImpersonation: boolean } };
|
||||
|
||||
export const TimelineCalendarEventParticipantFragmentFragmentDoc = gql`
|
||||
fragment TimelineCalendarEventParticipantFragment on TimelineCalendarEventParticipant {
|
||||
@ -2583,6 +2581,10 @@ export const UserQueryFragmentFragmentDoc = gql`
|
||||
subdomain
|
||||
hasValidEnterpriseKey
|
||||
hostname
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
featureFlags {
|
||||
id
|
||||
key
|
||||
@ -2607,6 +2609,11 @@ export const UserQueryFragmentFragmentDoc = gql`
|
||||
logo
|
||||
displayName
|
||||
subdomain
|
||||
hostname
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
userVars
|
||||
@ -3168,7 +3175,10 @@ export const ImpersonateDocument = gql`
|
||||
mutation Impersonate($userId: String!, $workspaceId: String!) {
|
||||
impersonate(userId: $userId, workspaceId: $workspaceId) {
|
||||
workspace {
|
||||
subdomain
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
id
|
||||
}
|
||||
loginToken {
|
||||
@ -3287,7 +3297,10 @@ export const SignUpDocument = gql`
|
||||
}
|
||||
workspace {
|
||||
id
|
||||
subdomain
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3369,8 +3382,10 @@ export const CheckUserExistsDocument = gql`
|
||||
availableWorkspaces {
|
||||
id
|
||||
displayName
|
||||
subdomain
|
||||
hostname
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
logo
|
||||
sso {
|
||||
type
|
||||
@ -3417,14 +3432,16 @@ export function useCheckUserExistsLazyQuery(baseOptions?: Apollo.LazyQueryHookOp
|
||||
export type CheckUserExistsQueryHookResult = ReturnType<typeof useCheckUserExistsQuery>;
|
||||
export type CheckUserExistsLazyQueryHookResult = ReturnType<typeof useCheckUserExistsLazyQuery>;
|
||||
export type CheckUserExistsQueryResult = Apollo.QueryResult<CheckUserExistsQuery, CheckUserExistsQueryVariables>;
|
||||
export const GetPublicWorkspaceDataBySubdomainDocument = gql`
|
||||
query GetPublicWorkspaceDataBySubdomain {
|
||||
getPublicWorkspaceDataBySubdomain {
|
||||
export const GetPublicWorkspaceDataByDomainDocument = gql`
|
||||
query GetPublicWorkspaceDataByDomain {
|
||||
getPublicWorkspaceDataByDomain {
|
||||
id
|
||||
logo
|
||||
displayName
|
||||
subdomain
|
||||
hostname
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
authProviders {
|
||||
sso {
|
||||
id
|
||||
@ -3443,31 +3460,31 @@ export const GetPublicWorkspaceDataBySubdomainDocument = gql`
|
||||
`;
|
||||
|
||||
/**
|
||||
* __useGetPublicWorkspaceDataBySubdomainQuery__
|
||||
* __useGetPublicWorkspaceDataByDomainQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useGetPublicWorkspaceDataBySubdomainQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useGetPublicWorkspaceDataBySubdomainQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* To run a query within a React component, call `useGetPublicWorkspaceDataByDomainQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useGetPublicWorkspaceDataByDomainQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useGetPublicWorkspaceDataBySubdomainQuery({
|
||||
* const { data, loading, error } = useGetPublicWorkspaceDataByDomainQuery({
|
||||
* variables: {
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useGetPublicWorkspaceDataBySubdomainQuery(baseOptions?: Apollo.QueryHookOptions<GetPublicWorkspaceDataBySubdomainQuery, GetPublicWorkspaceDataBySubdomainQueryVariables>) {
|
||||
export function useGetPublicWorkspaceDataByDomainQuery(baseOptions?: Apollo.QueryHookOptions<GetPublicWorkspaceDataByDomainQuery, GetPublicWorkspaceDataByDomainQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useQuery<GetPublicWorkspaceDataBySubdomainQuery, GetPublicWorkspaceDataBySubdomainQueryVariables>(GetPublicWorkspaceDataBySubdomainDocument, options);
|
||||
return Apollo.useQuery<GetPublicWorkspaceDataByDomainQuery, GetPublicWorkspaceDataByDomainQueryVariables>(GetPublicWorkspaceDataByDomainDocument, options);
|
||||
}
|
||||
export function useGetPublicWorkspaceDataBySubdomainLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<GetPublicWorkspaceDataBySubdomainQuery, GetPublicWorkspaceDataBySubdomainQueryVariables>) {
|
||||
export function useGetPublicWorkspaceDataByDomainLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<GetPublicWorkspaceDataByDomainQuery, GetPublicWorkspaceDataByDomainQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useLazyQuery<GetPublicWorkspaceDataBySubdomainQuery, GetPublicWorkspaceDataBySubdomainQueryVariables>(GetPublicWorkspaceDataBySubdomainDocument, options);
|
||||
return Apollo.useLazyQuery<GetPublicWorkspaceDataByDomainQuery, GetPublicWorkspaceDataByDomainQueryVariables>(GetPublicWorkspaceDataByDomainDocument, options);
|
||||
}
|
||||
export type GetPublicWorkspaceDataBySubdomainQueryHookResult = ReturnType<typeof useGetPublicWorkspaceDataBySubdomainQuery>;
|
||||
export type GetPublicWorkspaceDataBySubdomainLazyQueryHookResult = ReturnType<typeof useGetPublicWorkspaceDataBySubdomainLazyQuery>;
|
||||
export type GetPublicWorkspaceDataBySubdomainQueryResult = Apollo.QueryResult<GetPublicWorkspaceDataBySubdomainQuery, GetPublicWorkspaceDataBySubdomainQueryVariables>;
|
||||
export type GetPublicWorkspaceDataByDomainQueryHookResult = ReturnType<typeof useGetPublicWorkspaceDataByDomainQuery>;
|
||||
export type GetPublicWorkspaceDataByDomainLazyQueryHookResult = ReturnType<typeof useGetPublicWorkspaceDataByDomainLazyQuery>;
|
||||
export type GetPublicWorkspaceDataByDomainQueryResult = Apollo.QueryResult<GetPublicWorkspaceDataByDomainQuery, GetPublicWorkspaceDataByDomainQueryVariables>;
|
||||
export const ValidatePasswordResetTokenDocument = gql`
|
||||
query ValidatePasswordResetToken($token: String!) {
|
||||
validatePasswordResetToken(passwordResetToken: $token) {
|
||||
@ -4698,7 +4715,6 @@ export const ActivateWorkspaceDocument = gql`
|
||||
mutation ActivateWorkspace($input: ActivateWorkspaceInput!) {
|
||||
activateWorkspace(data: $input) {
|
||||
id
|
||||
subdomain
|
||||
}
|
||||
}
|
||||
`;
|
||||
@ -4887,7 +4903,6 @@ export const GetWorkspaceFromInviteHashDocument = gql`
|
||||
displayName
|
||||
logo
|
||||
allowImpersonation
|
||||
subdomain
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@ -4,7 +4,7 @@ import { Meta, StoryObj } from '@storybook/react';
|
||||
import { within } from '@storybook/test';
|
||||
import { HttpResponse, graphql } from 'msw';
|
||||
|
||||
import { GET_PUBLIC_WORKSPACE_DATA_BY_SUBDOMAIN } from '@/auth/graphql/queries/getPublicWorkspaceDataBySubdomain';
|
||||
import { GET_PUBLIC_WORKSPACE_DATA_BY_DOMAIN } from '@/auth/graphql/queries/getPublicWorkspaceDataByDomain';
|
||||
import { GET_CLIENT_CONFIG } from '@/client-config/graphql/queries/getClientConfig';
|
||||
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '@/object-metadata/graphql/queries';
|
||||
import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser';
|
||||
@ -36,7 +36,7 @@ const userMetadataLoaderMocks = {
|
||||
});
|
||||
}),
|
||||
graphql.query(
|
||||
getOperationName(GET_PUBLIC_WORKSPACE_DATA_BY_SUBDOMAIN) ?? '',
|
||||
getOperationName(GET_PUBLIC_WORKSPACE_DATA_BY_DOMAIN) ?? '',
|
||||
() => {
|
||||
return HttpResponse.json({
|
||||
data: {
|
||||
|
||||
@ -5,7 +5,10 @@ export const IMPERSONATE = gql`
|
||||
mutation Impersonate($userId: String!, $workspaceId: String!) {
|
||||
impersonate(userId: $userId, workspaceId: $workspaceId) {
|
||||
workspace {
|
||||
subdomain
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
id
|
||||
}
|
||||
loginToken {
|
||||
|
||||
@ -22,7 +22,10 @@ export const SIGN_UP = gql`
|
||||
}
|
||||
workspace {
|
||||
id
|
||||
subdomain
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,8 +9,10 @@ export const CHECK_USER_EXISTS = gql`
|
||||
availableWorkspaces {
|
||||
id
|
||||
displayName
|
||||
subdomain
|
||||
hostname
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
logo
|
||||
sso {
|
||||
type
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const GET_PUBLIC_WORKSPACE_DATA_BY_SUBDOMAIN = gql`
|
||||
query GetPublicWorkspaceDataBySubdomain {
|
||||
getPublicWorkspaceDataBySubdomain {
|
||||
export const GET_PUBLIC_WORKSPACE_DATA_BY_DOMAIN = gql`
|
||||
query GetPublicWorkspaceDataByDomain {
|
||||
getPublicWorkspaceDataByDomain {
|
||||
id
|
||||
logo
|
||||
displayName
|
||||
subdomain
|
||||
hostname
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
authProviders {
|
||||
sso {
|
||||
id
|
||||
@ -53,7 +53,7 @@ import { BillingCheckoutSession } from '@/auth/types/billingCheckoutSession.type
|
||||
import { captchaState } from '@/client-config/states/captchaState';
|
||||
import { isEmailVerificationRequiredState } from '@/client-config/states/isEmailVerificationRequiredState';
|
||||
import { isMultiWorkspaceEnabledState } from '@/client-config/states/isMultiWorkspaceEnabledState';
|
||||
import { useIsCurrentLocationOnAWorkspaceSubdomain } from '@/domain-manager/hooks/useIsCurrentLocationOnAWorkspaceSubdomain';
|
||||
import { useIsCurrentLocationOnAWorkspace } from '@/domain-manager/hooks/useIsCurrentLocationOnAWorkspace';
|
||||
import { useLastAuthenticatedWorkspaceDomain } from '@/domain-manager/hooks/useLastAuthenticatedWorkspaceDomain';
|
||||
import { useRedirect } from '@/domain-manager/hooks/useRedirect';
|
||||
import { useRedirectToWorkspaceDomain } from '@/domain-manager/hooks/useRedirectToWorkspaceDomain';
|
||||
@ -62,6 +62,7 @@ import { isAppWaitingForFreshObjectMetadataState } from '@/object-metadata/state
|
||||
import { workspaceAuthProvidersState } from '@/workspace/states/workspaceAuthProvidersState';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { dynamicActivate } from '~/utils/i18n/dynamicActivate';
|
||||
import { getWorkspaceUrl } from '~/utils/getWorkspaceUrl';
|
||||
|
||||
export const useAuth = () => {
|
||||
const setTokenPair = useSetRecoilState(tokenPairState);
|
||||
@ -96,8 +97,7 @@ export const useAuth = () => {
|
||||
useGetLoginTokenFromEmailVerificationTokenMutation();
|
||||
const [getCurrentUser] = useGetCurrentUserLazyQuery();
|
||||
|
||||
const { isOnAWorkspaceSubdomain } =
|
||||
useIsCurrentLocationOnAWorkspaceSubdomain();
|
||||
const { isOnAWorkspace } = useIsCurrentLocationOnAWorkspace();
|
||||
|
||||
const workspacePublicData = useRecoilValue(workspacePublicDataState);
|
||||
|
||||
@ -289,10 +289,10 @@ export const useAuth = () => {
|
||||
|
||||
setCurrentWorkspace(workspace);
|
||||
|
||||
if (isDefined(workspace) && isOnAWorkspaceSubdomain) {
|
||||
if (isDefined(workspace) && isOnAWorkspace) {
|
||||
setLastAuthenticateWorkspaceDomain({
|
||||
workspaceId: workspace.id,
|
||||
subdomain: workspace.subdomain,
|
||||
workspaceUrl: getWorkspaceUrl(workspace.workspaceUrls),
|
||||
});
|
||||
}
|
||||
|
||||
@ -315,7 +315,7 @@ export const useAuth = () => {
|
||||
};
|
||||
}, [
|
||||
getCurrentUser,
|
||||
isOnAWorkspaceSubdomain,
|
||||
isOnAWorkspace,
|
||||
setCurrentUser,
|
||||
setCurrentWorkspace,
|
||||
setCurrentWorkspaceMember,
|
||||
@ -413,7 +413,8 @@ export const useAuth = () => {
|
||||
|
||||
if (isMultiWorkspaceEnabled) {
|
||||
return redirectToWorkspaceDomain(
|
||||
signUpResult.data.signUp.workspace.subdomain,
|
||||
getWorkspaceUrl(signUpResult.data.signUp.workspace.workspaceUrls),
|
||||
|
||||
isEmailVerificationRequired ? AppPath.SignInUp : AppPath.Verify,
|
||||
{
|
||||
...(!isEmailVerificationRequired && {
|
||||
|
||||
@ -27,6 +27,7 @@ import { useRedirectToWorkspaceDomain } from '@/domain-manager/hooks/useRedirect
|
||||
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
import { getWorkspaceUrl } from '~/utils/getWorkspaceUrl';
|
||||
|
||||
const StyledContentContainer = styled(motion.div)`
|
||||
margin-bottom: ${({ theme }) => theme.spacing(8)};
|
||||
@ -92,9 +93,13 @@ export const SignInUpGlobalScopeForm = () => {
|
||||
if (response.__typename === 'UserExists') {
|
||||
if (response.availableWorkspaces.length >= 1) {
|
||||
const workspace = response.availableWorkspaces[0];
|
||||
return redirectToWorkspaceDomain(workspace.subdomain, pathname, {
|
||||
email: form.getValues('email'),
|
||||
});
|
||||
return redirectToWorkspaceDomain(
|
||||
getWorkspaceUrl(workspace.workspaceUrls),
|
||||
pathname,
|
||||
{
|
||||
email: form.getValues('email'),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
if (response.__typename === 'UserNotExists') {
|
||||
|
||||
@ -3,6 +3,7 @@ import { useSSO } from '@/auth/sign-in-up/hooks/useSSO';
|
||||
import { useRedirect } from '@/domain-manager/hooks/useRedirect';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
|
||||
jest.mock('@/ui/feedback/snack-bar-manager/hooks/useSnackBar');
|
||||
@ -52,9 +53,11 @@ const apolloMocks = [
|
||||
];
|
||||
|
||||
const Wrapper = ({ children }: { children: React.ReactNode }) => (
|
||||
<MockedProvider mocks={apolloMocks} addTypename={false}>
|
||||
{children}
|
||||
</MockedProvider>
|
||||
<MemoryRouter>
|
||||
<MockedProvider mocks={apolloMocks} addTypename={false}>
|
||||
{children}
|
||||
</MockedProvider>
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
describe('useSSO', () => {
|
||||
|
||||
@ -13,14 +13,16 @@ export const useSSO = () => {
|
||||
|
||||
const { enqueueSnackBar } = useSnackBar();
|
||||
const { redirect } = useRedirect();
|
||||
|
||||
const redirectToSSOLoginPage = async (identityProviderId: string) => {
|
||||
let authorizationUrlForSSOResult;
|
||||
try {
|
||||
authorizationUrlForSSOResult = await apolloClient.mutate({
|
||||
mutation: GET_AUTHORIZATION_URL,
|
||||
variables: {
|
||||
input: { identityProviderId, workspaceInviteHash },
|
||||
input: {
|
||||
identityProviderId,
|
||||
workspaceInviteHash,
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
|
||||
@ -21,6 +21,7 @@ export type CurrentWorkspace = Pick<
|
||||
| 'hasValidEnterpriseKey'
|
||||
| 'subdomain'
|
||||
| 'hostname'
|
||||
| 'workspaceUrls'
|
||||
| 'metadataVersion'
|
||||
>;
|
||||
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
import { createState } from '@ui/utilities/state/utils/createState';
|
||||
|
||||
import { Workspace } from '~/generated/graphql';
|
||||
|
||||
export type Workspaces = Pick<
|
||||
Workspace,
|
||||
'id' | 'logo' | 'displayName' | 'subdomain'
|
||||
'id' | 'logo' | 'displayName' | 'workspaceUrls'
|
||||
>[];
|
||||
|
||||
export const workspacesState = createState<Workspaces>({
|
||||
|
||||
@ -1,20 +1,12 @@
|
||||
import { domainConfigurationState } from '@/domain-manager/states/domainConfigurationState';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
|
||||
export const useBuildWorkspaceUrl = () => {
|
||||
const domainConfiguration = useRecoilValue(domainConfigurationState);
|
||||
|
||||
const buildWorkspaceUrl = (
|
||||
subdomain: string,
|
||||
endpoint: string,
|
||||
pathname?: string,
|
||||
searchParams?: Record<string, string>,
|
||||
searchParams?: Record<string, string | boolean>,
|
||||
) => {
|
||||
const url = new URL(window.location.href);
|
||||
|
||||
if (subdomain.length !== 0) {
|
||||
url.hostname = `${subdomain}.${domainConfiguration.frontDomain}`;
|
||||
}
|
||||
const url = new URL(endpoint);
|
||||
|
||||
if (isDefined(pathname)) {
|
||||
url.pathname = pathname;
|
||||
@ -22,7 +14,7 @@ export const useBuildWorkspaceUrl = () => {
|
||||
|
||||
if (isDefined(searchParams)) {
|
||||
Object.entries(searchParams).forEach(([key, value]) =>
|
||||
url.searchParams.set(key, value),
|
||||
url.searchParams.set(key, value.toString()),
|
||||
);
|
||||
}
|
||||
return url.toString();
|
||||
|
||||
@ -5,9 +5,9 @@ import { useRedirectToDefaultDomain } from '@/domain-manager/hooks/useRedirectTo
|
||||
import { workspaceAuthProvidersState } from '@/workspace/states/workspaceAuthProvidersState';
|
||||
import { useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
import { useGetPublicWorkspaceDataBySubdomainQuery } from '~/generated/graphql';
|
||||
import { useGetPublicWorkspaceDataByDomainQuery } from '~/generated/graphql';
|
||||
|
||||
export const useGetPublicWorkspaceDataBySubdomain = () => {
|
||||
export const useGetPublicWorkspaceDataByDomain = () => {
|
||||
const { isDefaultDomain } = useIsCurrentLocationOnDefaultDomain();
|
||||
const isMultiWorkspaceEnabled = useRecoilValue(isMultiWorkspaceEnabledState);
|
||||
const setWorkspaceAuthProviders = useSetRecoilState(
|
||||
@ -19,15 +19,15 @@ export const useGetPublicWorkspaceDataBySubdomain = () => {
|
||||
workspacePublicDataState,
|
||||
);
|
||||
|
||||
const { loading, data, error } = useGetPublicWorkspaceDataBySubdomainQuery({
|
||||
const { loading, data, error } = useGetPublicWorkspaceDataByDomainQuery({
|
||||
skip:
|
||||
(isMultiWorkspaceEnabled && isDefaultDomain) ||
|
||||
isDefined(workspacePublicData),
|
||||
onCompleted: (data) => {
|
||||
setWorkspaceAuthProviders(
|
||||
data.getPublicWorkspaceDataBySubdomain.authProviders,
|
||||
data.getPublicWorkspaceDataByDomain.authProviders,
|
||||
);
|
||||
setWorkspacePublicDataState(data.getPublicWorkspaceDataBySubdomain);
|
||||
setWorkspacePublicDataState(data.getPublicWorkspaceDataByDomain);
|
||||
},
|
||||
onError: (error) => {
|
||||
// eslint-disable-next-line no-console
|
||||
@ -38,7 +38,7 @@ export const useGetPublicWorkspaceDataBySubdomain = () => {
|
||||
|
||||
return {
|
||||
loading,
|
||||
data: data?.getPublicWorkspaceDataBySubdomain,
|
||||
data: data?.getPublicWorkspaceDataByDomain,
|
||||
error,
|
||||
};
|
||||
};
|
||||
@ -4,7 +4,7 @@ import { domainConfigurationState } from '@/domain-manager/states/domainConfigur
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
|
||||
export const useIsCurrentLocationOnAWorkspaceSubdomain = () => {
|
||||
export const useIsCurrentLocationOnAWorkspace = () => {
|
||||
const { defaultDomain } = useReadDefaultDomainFromConfiguration();
|
||||
|
||||
const isMultiWorkspaceEnabled = useRecoilValue(isMultiWorkspaceEnabledState);
|
||||
@ -18,10 +18,10 @@ export const useIsCurrentLocationOnAWorkspaceSubdomain = () => {
|
||||
throw new Error('frontDomain and defaultSubdomain are required');
|
||||
}
|
||||
|
||||
const isOnAWorkspaceSubdomain =
|
||||
const isOnAWorkspace =
|
||||
isMultiWorkspaceEnabled && window.location.hostname !== defaultDomain;
|
||||
|
||||
return {
|
||||
isOnAWorkspaceSubdomain,
|
||||
isOnAWorkspace,
|
||||
};
|
||||
};
|
||||
@ -8,7 +8,7 @@ export const useLastAuthenticatedWorkspaceDomain = () => {
|
||||
lastAuthenticatedWorkspaceDomainState,
|
||||
);
|
||||
const setLastAuthenticateWorkspaceDomainWithCookieAttributes = (
|
||||
params: { workspaceId: string; subdomain: string } | null,
|
||||
params: { workspaceId: string; workspaceUrl: string } | null,
|
||||
) => {
|
||||
setLastAuthenticatedWorkspaceDomain({
|
||||
...(params ? params : {}),
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
import { useIsCurrentLocationOnAWorkspaceSubdomain } from '@/domain-manager/hooks/useIsCurrentLocationOnAWorkspaceSubdomain';
|
||||
import { domainConfigurationState } from '@/domain-manager/states/domainConfigurationState';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
|
||||
export const useReadWorkspaceSubdomainFromCurrentLocation = () => {
|
||||
const domainConfiguration = useRecoilValue(domainConfigurationState);
|
||||
const { isOnAWorkspaceSubdomain } =
|
||||
useIsCurrentLocationOnAWorkspaceSubdomain();
|
||||
|
||||
if (!isDefined(domainConfiguration.frontDomain)) {
|
||||
throw new Error('frontDomain is not defined');
|
||||
}
|
||||
|
||||
const workspaceSubdomain = isOnAWorkspaceSubdomain
|
||||
? window.location.hostname.replace(
|
||||
`.${domainConfiguration.frontDomain}`,
|
||||
'',
|
||||
)
|
||||
: null;
|
||||
|
||||
return {
|
||||
workspaceSubdomain,
|
||||
};
|
||||
};
|
||||
@ -0,0 +1,11 @@
|
||||
import { useIsCurrentLocationOnAWorkspace } from '@/domain-manager/hooks/useIsCurrentLocationOnAWorkspace';
|
||||
|
||||
export const useReadWorkspaceUrlFromCurrentLocation = () => {
|
||||
const { isOnAWorkspace } = useIsCurrentLocationOnAWorkspace();
|
||||
|
||||
return {
|
||||
currentLocationHostname: isOnAWorkspace
|
||||
? window.location.hostname
|
||||
: undefined,
|
||||
};
|
||||
};
|
||||
@ -9,12 +9,12 @@ export const useRedirectToWorkspaceDomain = () => {
|
||||
const { redirect } = useRedirect();
|
||||
|
||||
const redirectToWorkspaceDomain = (
|
||||
subdomain: string,
|
||||
baseUrl: string,
|
||||
pathname?: string,
|
||||
searchParams?: Record<string, string>,
|
||||
searchParams?: Record<string, string | boolean>,
|
||||
) => {
|
||||
if (!isMultiWorkspaceEnabled) return;
|
||||
redirect(buildWorkspaceUrl(subdomain, pathname, searchParams));
|
||||
redirect(buildWorkspaceUrl(baseUrl, pathname, searchParams));
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@ -3,7 +3,7 @@ import { cookieStorageEffect } from '~/utils/recoil-effects';
|
||||
|
||||
export const lastAuthenticatedWorkspaceDomainState = createState<
|
||||
| {
|
||||
subdomain: string;
|
||||
workspaceUrl: string;
|
||||
workspaceId: string;
|
||||
cookieAttributes?: Cookies.CookieAttributes;
|
||||
}
|
||||
|
||||
@ -159,6 +159,10 @@ export const queries = {
|
||||
subdomain
|
||||
hasValidEnterpriseKey
|
||||
hostname
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
featureFlags {
|
||||
id
|
||||
key
|
||||
@ -183,6 +187,11 @@ export const queries = {
|
||||
logo
|
||||
displayName
|
||||
subdomain
|
||||
hostname
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
userVars
|
||||
@ -309,6 +318,10 @@ export const responseData = {
|
||||
isPasswordAuthEnabled: true,
|
||||
subdomain: 'test',
|
||||
hostname: null,
|
||||
workspaceUrls: {
|
||||
customUrl: undefined,
|
||||
subdomainUrl: 'https://test.twenty.com/',
|
||||
},
|
||||
featureFlags: [],
|
||||
metadataVersion: 1,
|
||||
currentBillingSubscription: null,
|
||||
|
||||
@ -27,6 +27,10 @@ const Wrapper = getJestMetadataAndApolloMocksWrapper({
|
||||
isGoogleAuthEnabled: true,
|
||||
isMicrosoftAuthEnabled: false,
|
||||
isPasswordAuthEnabled: true,
|
||||
workspaceUrls: {
|
||||
subdomainUrl: 'https://twenty.twenty.com',
|
||||
customUrl: 'https://my-custom-domain.com',
|
||||
},
|
||||
currentBillingSubscription: {
|
||||
id: '1',
|
||||
interval: SubscriptionInterval.Month,
|
||||
|
||||
@ -8,6 +8,7 @@ import { useState } from 'react';
|
||||
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
import { useImpersonateMutation } from '~/generated/graphql';
|
||||
import { getWorkspaceUrl } from '~/utils/getWorkspaceUrl';
|
||||
|
||||
export const useImpersonate = () => {
|
||||
const [currentUser] = useRecoilState(currentUserState);
|
||||
@ -55,9 +56,13 @@ export const useImpersonate = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
return redirectToWorkspaceDomain(workspace.subdomain, AppPath.Verify, {
|
||||
loginToken: loginToken.token,
|
||||
});
|
||||
return redirectToWorkspaceDomain(
|
||||
getWorkspaceUrl(workspace.workspaceUrls),
|
||||
AppPath.Verify,
|
||||
{
|
||||
loginToken: loginToken.token,
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
setError('Failed to impersonate user. Please try again.');
|
||||
setIsLoading(false);
|
||||
|
||||
@ -18,6 +18,7 @@ import {
|
||||
UndecoratedLink,
|
||||
} from 'twenty-ui';
|
||||
import { useRedirectToWorkspaceDomain } from '@/domain-manager/hooks/useRedirectToWorkspaceDomain';
|
||||
import { getWorkspaceUrl } from '~/utils/getWorkspaceUrl';
|
||||
|
||||
const StyledContainer = styled.div<{ isNavigationDrawerExpanded: boolean }>`
|
||||
align-items: center;
|
||||
@ -67,7 +68,7 @@ export const MultiWorkspaceDropdownButton = ({
|
||||
const { buildWorkspaceUrl } = useBuildWorkspaceUrl();
|
||||
|
||||
const handleChange = async (workspace: Workspaces[0]) => {
|
||||
redirectToWorkspaceDomain(workspace.subdomain);
|
||||
redirectToWorkspaceDomain(getWorkspaceUrl(workspace.workspaceUrls));
|
||||
};
|
||||
const [isNavigationDrawerExpanded] = useRecoilState(
|
||||
isNavigationDrawerExpandedState,
|
||||
@ -104,7 +105,7 @@ export const MultiWorkspaceDropdownButton = ({
|
||||
{workspaces.map((workspace) => (
|
||||
<UndecoratedLink
|
||||
key={workspace.id}
|
||||
to={buildWorkspaceUrl(workspace.subdomain)}
|
||||
to={buildWorkspaceUrl(getWorkspaceUrl(workspace.workspaceUrls))}
|
||||
onClick={(event) => {
|
||||
event?.preventDefault();
|
||||
handleChange(workspace);
|
||||
|
||||
@ -38,6 +38,10 @@ export const USER_QUERY_FRAGMENT = gql`
|
||||
subdomain
|
||||
hasValidEnterpriseKey
|
||||
hostname
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
featureFlags {
|
||||
id
|
||||
key
|
||||
@ -62,6 +66,11 @@ export const USER_QUERY_FRAGMENT = gql`
|
||||
logo
|
||||
displayName
|
||||
subdomain
|
||||
hostname
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
userVars
|
||||
|
||||
@ -1,17 +1,18 @@
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { isMultiWorkspaceEnabledState } from '@/client-config/states/isMultiWorkspaceEnabledState';
|
||||
import { useReadWorkspaceSubdomainFromCurrentLocation } from '@/domain-manager/hooks/useReadWorkspaceSubdomainFromCurrentLocation';
|
||||
import { useRedirectToWorkspaceDomain } from '@/domain-manager/hooks/useRedirectToWorkspaceDomain';
|
||||
import { lastAuthenticatedWorkspaceDomainState } from '@/domain-manager/states/lastAuthenticatedWorkspaceDomainState';
|
||||
import { useEffect } from 'react';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
import { isMultiWorkspaceEnabledState } from '@/client-config/states/isMultiWorkspaceEnabledState';
|
||||
import { useRedirectToWorkspaceDomain } from '@/domain-manager/hooks/useRedirectToWorkspaceDomain';
|
||||
import { lastAuthenticatedWorkspaceDomainState } from '@/domain-manager/states/lastAuthenticatedWorkspaceDomainState';
|
||||
import { useReadWorkspaceUrlFromCurrentLocation } from '@/domain-manager/hooks/useReadWorkspaceUrlFromCurrentLocation';
|
||||
|
||||
import { useGetPublicWorkspaceDataBySubdomain } from '@/domain-manager/hooks/useGetPublicWorkspaceDataBySubdomain';
|
||||
import { useIsCurrentLocationOnDefaultDomain } from '@/domain-manager/hooks/useIsCurrentLocationOnDefaultDomain';
|
||||
import { useGetPublicWorkspaceDataByDomain } from '@/domain-manager/hooks/useGetPublicWorkspaceDataByDomain';
|
||||
import { WorkspaceUrls } from '~/generated/graphql';
|
||||
import { getWorkspaceUrl } from '~/utils/getWorkspaceUrl';
|
||||
export const WorkspaceProviderEffect = () => {
|
||||
const { data: getPublicWorkspaceData } =
|
||||
useGetPublicWorkspaceDataBySubdomain();
|
||||
const { data: getPublicWorkspaceData } = useGetPublicWorkspaceDataByDomain();
|
||||
|
||||
const lastAuthenticatedWorkspaceDomain = useRecoilValue(
|
||||
lastAuthenticatedWorkspaceDomainState,
|
||||
@ -20,23 +21,38 @@ export const WorkspaceProviderEffect = () => {
|
||||
const { redirectToWorkspaceDomain } = useRedirectToWorkspaceDomain();
|
||||
const { isDefaultDomain } = useIsCurrentLocationOnDefaultDomain();
|
||||
|
||||
const { workspaceSubdomain } = useReadWorkspaceSubdomainFromCurrentLocation();
|
||||
const { currentLocationHostname } = useReadWorkspaceUrlFromCurrentLocation();
|
||||
|
||||
const isMultiWorkspaceEnabled = useRecoilValue(isMultiWorkspaceEnabledState);
|
||||
|
||||
const getHostnamesFromWorkspaceUrls = (workspaceUrls: WorkspaceUrls) => {
|
||||
return {
|
||||
customUrlHostname: workspaceUrls.customUrl
|
||||
? new URL(workspaceUrls.customUrl).hostname
|
||||
: undefined,
|
||||
subdomainUrlHostname: new URL(workspaceUrls.subdomainUrl).hostname,
|
||||
};
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const hostnames = getPublicWorkspaceData
|
||||
? getHostnamesFromWorkspaceUrls(getPublicWorkspaceData?.workspaceUrls)
|
||||
: null;
|
||||
if (
|
||||
isMultiWorkspaceEnabled &&
|
||||
isDefined(getPublicWorkspaceData?.subdomain) &&
|
||||
getPublicWorkspaceData.subdomain !== workspaceSubdomain
|
||||
isDefined(getPublicWorkspaceData) &&
|
||||
currentLocationHostname !== hostnames?.customUrlHostname &&
|
||||
currentLocationHostname !== hostnames?.subdomainUrlHostname
|
||||
) {
|
||||
redirectToWorkspaceDomain(getPublicWorkspaceData.subdomain);
|
||||
redirectToWorkspaceDomain(
|
||||
getWorkspaceUrl(getPublicWorkspaceData.workspaceUrls),
|
||||
);
|
||||
}
|
||||
}, [
|
||||
workspaceSubdomain,
|
||||
isMultiWorkspaceEnabled,
|
||||
redirectToWorkspaceDomain,
|
||||
getPublicWorkspaceData,
|
||||
currentLocationHostname,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
@ -44,10 +60,10 @@ export const WorkspaceProviderEffect = () => {
|
||||
isMultiWorkspaceEnabled &&
|
||||
isDefaultDomain &&
|
||||
isDefined(lastAuthenticatedWorkspaceDomain) &&
|
||||
'subdomain' in lastAuthenticatedWorkspaceDomain &&
|
||||
isDefined(lastAuthenticatedWorkspaceDomain?.subdomain)
|
||||
'workspaceUrl' in lastAuthenticatedWorkspaceDomain &&
|
||||
isDefined(lastAuthenticatedWorkspaceDomain?.workspaceUrl)
|
||||
) {
|
||||
redirectToWorkspaceDomain(lastAuthenticatedWorkspaceDomain.subdomain);
|
||||
redirectToWorkspaceDomain(lastAuthenticatedWorkspaceDomain.workspaceUrl);
|
||||
}
|
||||
}, [
|
||||
isMultiWorkspaceEnabled,
|
||||
|
||||
@ -4,7 +4,6 @@ export const ACTIVATE_WORKSPACE = gql`
|
||||
mutation ActivateWorkspace($input: ActivateWorkspaceInput!) {
|
||||
activateWorkspace(data: $input) {
|
||||
id
|
||||
subdomain
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@ -7,7 +7,6 @@ export const GET_WORKSPACE_FROM_INVITE_HASH = gql`
|
||||
displayName
|
||||
logo
|
||||
allowImpersonation
|
||||
subdomain
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@ -13,8 +13,8 @@ import { SignInUpSSOIdentityProviderSelection } from '@/auth/sign-in-up/componen
|
||||
import { SignInUpWorkspaceScopeForm } from '@/auth/sign-in-up/components/SignInUpWorkspaceScopeForm';
|
||||
import { SignInUpWorkspaceScopeFormEffect } from '@/auth/sign-in-up/components/SignInUpWorkspaceScopeFormEffect';
|
||||
import { isMultiWorkspaceEnabledState } from '@/client-config/states/isMultiWorkspaceEnabledState';
|
||||
import { useGetPublicWorkspaceDataBySubdomain } from '@/domain-manager/hooks/useGetPublicWorkspaceDataBySubdomain';
|
||||
import { useIsCurrentLocationOnAWorkspaceSubdomain } from '@/domain-manager/hooks/useIsCurrentLocationOnAWorkspaceSubdomain';
|
||||
import { useGetPublicWorkspaceDataByDomain } from '@/domain-manager/hooks/useGetPublicWorkspaceDataByDomain';
|
||||
import { useIsCurrentLocationOnAWorkspace } from '@/domain-manager/hooks/useIsCurrentLocationOnAWorkspace';
|
||||
import { useIsCurrentLocationOnDefaultDomain } from '@/domain-manager/hooks/useIsCurrentLocationOnDefaultDomain';
|
||||
import { DEFAULT_WORKSPACE_NAME } from '@/ui/navigation/navigation-drawer/constants/DefaultWorkspaceName';
|
||||
import { useMemo } from 'react';
|
||||
@ -24,7 +24,7 @@ import { AnimatedEaseIn } from 'twenty-ui';
|
||||
import { useWorkspaceFromInviteHash } from '@/auth/sign-in-up/hooks/useWorkspaceFromInviteHash';
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { PublicWorkspaceDataOutput } from '~/generated-metadata/graphql';
|
||||
import { PublicWorkspaceDataOutput } from '~/generated/graphql';
|
||||
|
||||
const StandardContent = ({
|
||||
workspacePublicData,
|
||||
@ -55,10 +55,9 @@ export const SignInUp = () => {
|
||||
const { form } = useSignInUpForm();
|
||||
const { signInUpStep } = useSignInUp(form);
|
||||
const { isDefaultDomain } = useIsCurrentLocationOnDefaultDomain();
|
||||
const { isOnAWorkspaceSubdomain } =
|
||||
useIsCurrentLocationOnAWorkspaceSubdomain();
|
||||
const { isOnAWorkspace } = useIsCurrentLocationOnAWorkspace();
|
||||
const workspacePublicData = useRecoilValue(workspacePublicDataState);
|
||||
const { loading } = useGetPublicWorkspaceDataBySubdomain();
|
||||
const { loading } = useGetPublicWorkspaceDataByDomain();
|
||||
const isMultiWorkspaceEnabled = useRecoilValue(isMultiWorkspaceEnabledState);
|
||||
const { workspaceInviteHash, workspace: workspaceFromInviteHash } =
|
||||
useWorkspaceFromInviteHash();
|
||||
@ -91,7 +90,7 @@ export const SignInUp = () => {
|
||||
|
||||
if (
|
||||
(!isMultiWorkspaceEnabled ||
|
||||
(isMultiWorkspaceEnabled && isOnAWorkspaceSubdomain)) &&
|
||||
(isMultiWorkspaceEnabled && isOnAWorkspace)) &&
|
||||
signInUpStep === SignInUpStep.SSOIdentityProviderSelection
|
||||
) {
|
||||
return <SignInUpSSOIdentityProviderSelection />;
|
||||
@ -99,7 +98,7 @@ export const SignInUp = () => {
|
||||
|
||||
if (
|
||||
isDefined(workspacePublicData) &&
|
||||
(!isMultiWorkspaceEnabled || isOnAWorkspaceSubdomain)
|
||||
(!isMultiWorkspaceEnabled || isOnAWorkspace)
|
||||
) {
|
||||
return (
|
||||
<>
|
||||
@ -113,7 +112,7 @@ export const SignInUp = () => {
|
||||
}, [
|
||||
isDefaultDomain,
|
||||
isMultiWorkspaceEnabled,
|
||||
isOnAWorkspaceSubdomain,
|
||||
isOnAWorkspace,
|
||||
loading,
|
||||
signInUpStep,
|
||||
workspacePublicData,
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { ApolloError } from '@apollo/client';
|
||||
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons';
|
||||
@ -13,7 +14,6 @@ import { SettingsSubdomain } from '~/pages/settings/workspace/SettingsSubdomain'
|
||||
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
|
||||
import { useNavigateSettings } from '~/hooks/useNavigateSettings';
|
||||
import { getSettingsPath } from '~/utils/navigation/getSettingsPath';
|
||||
import { ApolloError } from '@apollo/client';
|
||||
import { Trans, useLingui } from '@lingui/react/macro';
|
||||
import { z } from 'zod';
|
||||
import { FormProvider, useForm } from 'react-hook-form';
|
||||
@ -94,12 +94,18 @@ export const SettingsDomain = () => {
|
||||
});
|
||||
},
|
||||
onCompleted: () => {
|
||||
const currentUrl = new URL(window.location.href);
|
||||
|
||||
currentUrl.hostname = new URL(
|
||||
currentWorkspace.workspaceUrls.subdomainUrl,
|
||||
).hostname.replace(currentWorkspace.subdomain, values.subdomain);
|
||||
|
||||
setCurrentWorkspace({
|
||||
...currentWorkspace,
|
||||
subdomain: values.subdomain,
|
||||
});
|
||||
|
||||
redirectToWorkspaceDomain(values.subdomain);
|
||||
redirectToWorkspaceDomain(currentUrl.toString());
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
|
||||
import { useRedirectToWorkspaceDomain } from '@/domain-manager/hooks/useRedirectToWorkspaceDomain';
|
||||
import { TextInputV2 } from '@/ui/input/components/TextInputV2';
|
||||
import styled from '@emotion/styled';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
@ -41,7 +40,6 @@ export const SettingsHostname = () => {
|
||||
const [updateWorkspace] = useUpdateWorkspaceMutation();
|
||||
const { data: getHostnameDetailsData } = useGetHostnameDetailsQuery();
|
||||
|
||||
const { redirectToWorkspaceDomain } = useRedirectToWorkspaceDomain();
|
||||
const { t } = useLingui();
|
||||
|
||||
const [currentWorkspace, setCurrentWorkspace] = useRecoilState(
|
||||
@ -75,8 +73,6 @@ export const SettingsHostname = () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
redirectToWorkspaceDomain(currentWorkspace.subdomain);
|
||||
} catch (error) {
|
||||
control.setError('hostname', {
|
||||
type: 'manual',
|
||||
@ -106,8 +102,6 @@ export const SettingsHostname = () => {
|
||||
...currentWorkspace,
|
||||
hostname: values.hostname,
|
||||
});
|
||||
|
||||
// redirectToWorkspaceDomain(values.subdomain);
|
||||
} catch (error) {
|
||||
control.setError('hostname', {
|
||||
type: 'manual',
|
||||
@ -139,12 +133,36 @@ export const SettingsHostname = () => {
|
||||
{isDefined(getHostnameDetailsData?.getHostnameDetails?.hostname) && (
|
||||
<pre>
|
||||
{getHostnameDetailsData.getHostnameDetails.hostname} CNAME
|
||||
app.twenty-main.com
|
||||
twenty-main.com
|
||||
</pre>
|
||||
)}
|
||||
{getHostnameDetailsData && (
|
||||
<pre>{JSON.stringify(getHostnameDetailsData, null, 4)}</pre>
|
||||
)}
|
||||
{getHostnameDetailsData?.getHostnameDetails &&
|
||||
getHostnameDetailsData.getHostnameDetails.ownershipVerifications.map(
|
||||
(ownershipVerification) => {
|
||||
if (
|
||||
ownershipVerification.__typename ===
|
||||
'CustomHostnameOwnershipVerificationTxt'
|
||||
) {
|
||||
return (
|
||||
<pre>
|
||||
{ownershipVerification.name} TXT {ownershipVerification.value}
|
||||
</pre>
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
ownershipVerification.__typename ===
|
||||
'CustomHostnameOwnershipVerificationHttp'
|
||||
) {
|
||||
return (
|
||||
<pre>
|
||||
{ownershipVerification.url} HTTP {ownershipVerification.body}
|
||||
</pre>
|
||||
);
|
||||
}
|
||||
return <></>;
|
||||
},
|
||||
)}
|
||||
</Section>
|
||||
);
|
||||
};
|
||||
|
||||
@ -20,7 +20,7 @@ import { mockedUserData } from '~/testing/mock-data/users';
|
||||
import { mockedViewsData } from '~/testing/mock-data/views';
|
||||
import { mockWorkspaceMembers } from '~/testing/mock-data/workspace-members';
|
||||
|
||||
import { GET_PUBLIC_WORKSPACE_DATA_BY_SUBDOMAIN } from '@/auth/graphql/queries/getPublicWorkspaceDataBySubdomain';
|
||||
import { GET_PUBLIC_WORKSPACE_DATA_BY_DOMAIN } from '@/auth/graphql/queries/getPublicWorkspaceDataByDomain';
|
||||
import { mockedStandardObjectMetadataQueryResult } from '~/testing/mock-data/generated/mock-metadata-query-result';
|
||||
import { mockedTasks } from '~/testing/mock-data/tasks';
|
||||
import {
|
||||
@ -49,15 +49,18 @@ export const graphqlMocks = {
|
||||
});
|
||||
}),
|
||||
graphql.query(
|
||||
getOperationName(GET_PUBLIC_WORKSPACE_DATA_BY_SUBDOMAIN) ?? '',
|
||||
getOperationName(GET_PUBLIC_WORKSPACE_DATA_BY_DOMAIN) ?? '',
|
||||
() => {
|
||||
return HttpResponse.json({
|
||||
data: {
|
||||
getPublicWorkspaceDataBySubdomain: {
|
||||
getPublicWorkspaceDataByDomain: {
|
||||
id: 'id',
|
||||
logo: 'logo',
|
||||
displayName: 'displayName',
|
||||
subdomain: 'subdomain',
|
||||
workspaceUrls: {
|
||||
customUrl: undefined,
|
||||
subdomainUrl: 'https://twenty.com',
|
||||
},
|
||||
authProviders: {
|
||||
google: true,
|
||||
microsoft: false,
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
import { GetPublicWorkspaceDataBySubdomainQuery } from '~/generated/graphql';
|
||||
import { GetPublicWorkspaceDataByDomainQuery } from '~/generated/graphql';
|
||||
|
||||
export const mockedPublicWorkspaceDataBySubdomain: GetPublicWorkspaceDataBySubdomainQuery['getPublicWorkspaceDataBySubdomain'] =
|
||||
export const mockedPublicWorkspaceDataBySubdomain: GetPublicWorkspaceDataByDomainQuery['getPublicWorkspaceDataByDomain'] =
|
||||
{
|
||||
__typename: 'PublicWorkspaceDataOutput',
|
||||
id: '9870323e-22c3-4d14-9b7f-5bdc84f7d6ee',
|
||||
logo: 'workspace-logo/original/c88deb49-7636-4560-918d-08c3265ffb20.49?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3b3Jrc3BhY2VJZCI6Ijk4NzAzMjNlLTIyYzMtNGQxNC05YjdmLTViZGM4NGY3ZDZlZSIsImlhdCI6MTczNjU0MDU0MywiZXhwIjoxNzM2NjI2OTQzfQ.C8cnHu09VGseRbQAMM4nhiO6z4TLG03ntFTvxm53-xg',
|
||||
displayName: 'Twenty Eng',
|
||||
subdomain: 'twenty-eng',
|
||||
workspaceUrls: {
|
||||
customUrl: 'https://twenty-eng.com',
|
||||
subdomainUrl: 'https://custom.twenty.com',
|
||||
},
|
||||
authProviders: {
|
||||
__typename: 'AuthProviders',
|
||||
sso: [],
|
||||
|
||||
@ -48,6 +48,10 @@ export const mockCurrentWorkspace: Workspace = {
|
||||
hasValidEnterpriseKey: false,
|
||||
isGoogleAuthEnabled: true,
|
||||
isPasswordAuthEnabled: true,
|
||||
workspaceUrls: {
|
||||
customUrl: undefined,
|
||||
subdomainUrl: 'twenty.twenty.com',
|
||||
},
|
||||
isMicrosoftAuthEnabled: false,
|
||||
featureFlags: [
|
||||
{
|
||||
|
||||
5
packages/twenty-front/src/utils/getWorkspaceUrl.ts
Normal file
5
packages/twenty-front/src/utils/getWorkspaceUrl.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { WorkspaceUrls } from '~/generated/graphql';
|
||||
|
||||
export const getWorkspaceUrl = (workspaceUrls: WorkspaceUrls) => {
|
||||
return workspaceUrls.customUrl ?? workspaceUrls.subdomainUrl;
|
||||
};
|
||||
@ -48,7 +48,7 @@ export const seedFeatureFlags = async (
|
||||
{
|
||||
key: FeatureFlagKey.IsCustomDomainEnabled,
|
||||
workspaceId: workspaceId,
|
||||
value: true,
|
||||
value: false,
|
||||
},
|
||||
{
|
||||
key: FeatureFlagKey.IsBillingPlansEnabled,
|
||||
|
||||
@ -60,7 +60,7 @@ export class CoreQueryBuilderFactory {
|
||||
throw new BadRequestException(
|
||||
`No object was found for the workspace associated with this API key. You may generate a new one here ${this.domainManagerService
|
||||
.buildWorkspaceURL({
|
||||
subdomain: workspace.subdomain,
|
||||
workspace,
|
||||
pathname: '/settings/developers',
|
||||
})
|
||||
.toString()}`,
|
||||
|
||||
@ -13,6 +13,7 @@ import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/featu
|
||||
import { FeatureFlag } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
|
||||
import { User } from 'src/engine/core-modules/user/user.entity';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { DomainManagerService } from 'src/engine/core-modules/domain-manager/services/domain-manager.service';
|
||||
|
||||
const UserFindOneMock = jest.fn();
|
||||
const WorkspaceFindOneMock = jest.fn();
|
||||
@ -95,6 +96,15 @@ describe('AdminPanelService', () => {
|
||||
generateLoginToken: LoginTokenServiceGenerateLoginTokenMock,
|
||||
},
|
||||
},
|
||||
{
|
||||
provide: DomainManagerService,
|
||||
useValue: {
|
||||
getworkspaceUrls: jest.fn().mockReturnValue({
|
||||
customUrl: undefined,
|
||||
subdomainUrl: 'https://twenty.twenty.com',
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
provide: EnvironmentService,
|
||||
useValue: {
|
||||
@ -230,7 +240,10 @@ describe('AdminPanelService', () => {
|
||||
expect.objectContaining({
|
||||
workspace: {
|
||||
id: 'workspace-id',
|
||||
subdomain: 'example-subdomain',
|
||||
workspaceUrls: {
|
||||
customUrl: undefined,
|
||||
subdomainUrl: 'https://twenty.twenty.com',
|
||||
},
|
||||
},
|
||||
loginToken: expect.objectContaining({
|
||||
token: 'mock-login-token',
|
||||
|
||||
@ -7,11 +7,13 @@ import { AuthModule } from 'src/engine/core-modules/auth/auth.module';
|
||||
import { FeatureFlag } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
|
||||
import { User } from 'src/engine/core-modules/user/user.entity';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { DomainManagerModule } from 'src/engine/core-modules/domain-manager/domain-manager.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([User, Workspace, FeatureFlag], 'core'),
|
||||
AuthModule,
|
||||
DomainManagerModule,
|
||||
],
|
||||
providers: [AdminPanelResolver, AdminPanelService],
|
||||
exports: [AdminPanelService],
|
||||
|
||||
@ -28,12 +28,14 @@ import { User } from 'src/engine/core-modules/user/user.entity';
|
||||
import { userValidator } from 'src/engine/core-modules/user/user.validate';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { workspaceValidator } from 'src/engine/core-modules/workspace/workspace.validate';
|
||||
import { DomainManagerService } from 'src/engine/core-modules/domain-manager/services/domain-manager.service';
|
||||
|
||||
@Injectable()
|
||||
export class AdminPanelService {
|
||||
constructor(
|
||||
private readonly loginTokenService: LoginTokenService,
|
||||
private readonly environmentService: EnvironmentService,
|
||||
private readonly domainManagerService: DomainManagerService,
|
||||
@InjectRepository(User, 'core')
|
||||
private readonly userRepository: Repository<User>,
|
||||
@InjectRepository(Workspace, 'core')
|
||||
@ -72,7 +74,9 @@ export class AdminPanelService {
|
||||
return {
|
||||
workspace: {
|
||||
id: user.workspaces[0].workspace.id,
|
||||
subdomain: user.workspaces[0].workspace.subdomain,
|
||||
workspaceUrls: this.domainManagerService.getworkspaceUrls(
|
||||
user.workspaces[0].workspace,
|
||||
),
|
||||
},
|
||||
loginToken,
|
||||
};
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
import { AuthToken } from 'src/engine/core-modules/auth/dto/token.entity';
|
||||
import { WorkspaceSubdomainAndId } from 'src/engine/core-modules/workspace/dtos/workspace-subdomain-id.dto';
|
||||
import { workspaceUrlsAndId } from 'src/engine/core-modules/workspace/dtos/workspace-subdomain-id.dto';
|
||||
|
||||
@ObjectType()
|
||||
export class ImpersonateOutput {
|
||||
@Field(() => AuthToken)
|
||||
loginToken: AuthToken;
|
||||
|
||||
@Field(() => WorkspaceSubdomainAndId)
|
||||
workspace: WorkspaceSubdomainAndId;
|
||||
@Field(() => workspaceUrlsAndId)
|
||||
workspace: workspaceUrlsAndId;
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ export class AuthResolver {
|
||||
await this.emailVerificationService.sendVerificationEmail(
|
||||
user.id,
|
||||
user.email,
|
||||
workspace.subdomain,
|
||||
workspace,
|
||||
);
|
||||
|
||||
const loginToken = await this.loginTokenService.generateLoginToken(
|
||||
@ -233,7 +233,7 @@ export class AuthResolver {
|
||||
loginToken,
|
||||
workspace: {
|
||||
id: workspace.id,
|
||||
subdomain: workspace.subdomain,
|
||||
workspaceUrls: this.domainManagerService.getworkspaceUrls(workspace),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ export class GoogleAPIsAuthController {
|
||||
return res.redirect(
|
||||
this.domainManagerService
|
||||
.buildWorkspaceURL({
|
||||
subdomain: workspace.subdomain,
|
||||
workspace,
|
||||
pathname: redirectLocation || '/settings/accounts',
|
||||
})
|
||||
.toString(),
|
||||
|
||||
@ -19,7 +19,6 @@ import { AuthService } from 'src/engine/core-modules/auth/services/auth.service'
|
||||
import { GoogleRequest } from 'src/engine/core-modules/auth/strategies/google.auth.strategy';
|
||||
import { LoginTokenService } from 'src/engine/core-modules/auth/token/services/login-token.service';
|
||||
import { User } from 'src/engine/core-modules/user/user.entity';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { GuardRedirectService } from 'src/engine/core-modules/guard-redirect/services/guard-redirect.service';
|
||||
|
||||
@Controller('auth/google')
|
||||
@ -28,7 +27,6 @@ export class GoogleAuthController {
|
||||
constructor(
|
||||
private readonly loginTokenService: LoginTokenService,
|
||||
private readonly authService: AuthService,
|
||||
private readonly environmentService: EnvironmentService,
|
||||
private readonly guardRedirectService: GuardRedirectService,
|
||||
@InjectRepository(User, 'core')
|
||||
private readonly userRepository: Repository<User>,
|
||||
@ -110,7 +108,7 @@ export class GoogleAuthController {
|
||||
return res.redirect(
|
||||
this.authService.computeRedirectURI({
|
||||
loginToken: loginToken.token,
|
||||
subdomain: workspace.subdomain,
|
||||
workspace,
|
||||
billingCheckoutSessionState,
|
||||
}),
|
||||
);
|
||||
@ -118,9 +116,9 @@ export class GoogleAuthController {
|
||||
return res.redirect(
|
||||
this.guardRedirectService.getRedirectErrorUrlAndCaptureExceptions(
|
||||
err,
|
||||
currentWorkspace ?? {
|
||||
subdomain: this.environmentService.get('DEFAULT_SUBDOMAIN'),
|
||||
},
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
currentWorkspace,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ export class MicrosoftAPIsAuthController {
|
||||
return res.redirect(
|
||||
this.domainManagerService
|
||||
.buildWorkspaceURL({
|
||||
subdomain: workspace.subdomain,
|
||||
workspace,
|
||||
pathname: redirectLocation || '/settings/accounts',
|
||||
})
|
||||
.toString(),
|
||||
|
||||
@ -18,7 +18,6 @@ import { AuthService } from 'src/engine/core-modules/auth/services/auth.service'
|
||||
import { MicrosoftRequest } from 'src/engine/core-modules/auth/strategies/microsoft.auth.strategy';
|
||||
import { LoginTokenService } from 'src/engine/core-modules/auth/token/services/login-token.service';
|
||||
import { User } from 'src/engine/core-modules/user/user.entity';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { GuardRedirectService } from 'src/engine/core-modules/guard-redirect/services/guard-redirect.service';
|
||||
|
||||
@Controller('auth/microsoft')
|
||||
@ -28,7 +27,6 @@ export class MicrosoftAuthController {
|
||||
private readonly loginTokenService: LoginTokenService,
|
||||
private readonly authService: AuthService,
|
||||
private readonly guardRedirectService: GuardRedirectService,
|
||||
private readonly environmentService: EnvironmentService,
|
||||
@InjectRepository(User, 'core')
|
||||
private readonly userRepository: Repository<User>,
|
||||
) {}
|
||||
@ -111,8 +109,7 @@ export class MicrosoftAuthController {
|
||||
return res.redirect(
|
||||
this.authService.computeRedirectURI({
|
||||
loginToken: loginToken.token,
|
||||
subdomain: workspace.subdomain,
|
||||
|
||||
workspace,
|
||||
billingCheckoutSessionState,
|
||||
}),
|
||||
);
|
||||
@ -120,9 +117,9 @@ export class MicrosoftAuthController {
|
||||
return res.redirect(
|
||||
this.guardRedirectService.getRedirectErrorUrlAndCaptureExceptions(
|
||||
err,
|
||||
currentWorkspace ?? {
|
||||
subdomain: this.environmentService.get('DEFAULT_SUBDOMAIN'),
|
||||
},
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
currentWorkspace,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -32,7 +32,6 @@ import {
|
||||
} from 'src/engine/core-modules/sso/workspace-sso-identity-provider.entity';
|
||||
import { User } from 'src/engine/core-modules/user/user.entity';
|
||||
import { AuthOAuthExceptionFilter } from 'src/engine/core-modules/auth/filters/auth-oauth-exception.filter';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { GuardRedirectService } from 'src/engine/core-modules/guard-redirect/services/guard-redirect.service';
|
||||
import { SAMLRequest } from 'src/engine/core-modules/auth/strategies/saml.auth.strategy';
|
||||
import { OIDCRequest } from 'src/engine/core-modules/auth/strategies/oidc.auth.strategy';
|
||||
@ -45,7 +44,6 @@ export class SSOAuthController {
|
||||
private readonly loginTokenService: LoginTokenService,
|
||||
private readonly authService: AuthService,
|
||||
private readonly guardRedirectService: GuardRedirectService,
|
||||
private readonly environmentService: EnvironmentService,
|
||||
private readonly sSOService: SSOService,
|
||||
@InjectRepository(User, 'core')
|
||||
private readonly userRepository: Repository<User>,
|
||||
@ -152,16 +150,16 @@ export class SSOAuthController {
|
||||
return res.redirect(
|
||||
this.authService.computeRedirectURI({
|
||||
loginToken: loginToken.token,
|
||||
subdomain: currentWorkspace.subdomain,
|
||||
workspace: currentWorkspace,
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
return res.redirect(
|
||||
this.guardRedirectService.getRedirectErrorUrlAndCaptureExceptions(
|
||||
err,
|
||||
workspaceIdentityProvider?.workspace ?? {
|
||||
subdomain: this.environmentService.get('DEFAULT_SUBDOMAIN'),
|
||||
},
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
workspaceIdentityProvider?.workspace,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import {
|
||||
IdentityProviderType,
|
||||
SSOIdentityProviderStatus,
|
||||
} from 'src/engine/core-modules/sso/workspace-sso-identity-provider.entity';
|
||||
import { workspaceUrls } from 'src/engine/core-modules/workspace/dtos/workspace-endpoints.dto';
|
||||
|
||||
@ObjectType()
|
||||
class SSOConnection {
|
||||
@ -34,8 +35,8 @@ export class AvailableWorkspaceOutput {
|
||||
@Field(() => String, { nullable: true })
|
||||
displayName?: string;
|
||||
|
||||
@Field(() => String)
|
||||
subdomain: string;
|
||||
@Field(() => workspaceUrls)
|
||||
workspaceUrls: workspaceUrls;
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
hostname?: string;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
import { WorkspaceSubdomainAndId } from 'src/engine/core-modules/workspace/dtos/workspace-subdomain-id.dto';
|
||||
import { workspaceUrlsAndId } from 'src/engine/core-modules/workspace/dtos/workspace-subdomain-id.dto';
|
||||
|
||||
import { AuthToken } from './token.entity';
|
||||
|
||||
@ -9,6 +9,6 @@ export class SignUpOutput {
|
||||
@Field(() => AuthToken)
|
||||
loginToken: AuthToken;
|
||||
|
||||
@Field(() => WorkspaceSubdomainAndId)
|
||||
workspace: WorkspaceSubdomainAndId;
|
||||
@Field(() => workspaceUrlsAndId)
|
||||
workspace: workspaceUrlsAndId;
|
||||
}
|
||||
|
||||
@ -27,9 +27,11 @@ export class EnterpriseFeaturesEnabledGuard implements CanActivate {
|
||||
|
||||
return true;
|
||||
} catch (err) {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(context, err, {
|
||||
subdomain: this.guardRedirectService.getSubdomainFromContext(context),
|
||||
});
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromContext(context),
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -50,9 +50,11 @@ export class GoogleAPIsOauthExchangeCodeForTokenGuard extends AuthGuard(
|
||||
|
||||
return (await super.canActivate(context)) as boolean;
|
||||
} catch (err) {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(context, err, {
|
||||
subdomain: this.guardRedirectService.getSubdomainFromContext(context),
|
||||
});
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromContext(context),
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -71,9 +71,9 @@ export class GoogleAPIsOauthRequestCodeGuard extends AuthGuard('google-apis') {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
workspace ?? {
|
||||
subdomain: this.environmentService.get('DEFAULT_SUBDOMAIN'),
|
||||
},
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
workspace,
|
||||
),
|
||||
);
|
||||
|
||||
return false;
|
||||
|
||||
@ -11,13 +11,11 @@ import {
|
||||
} from 'src/engine/core-modules/auth/auth.exception';
|
||||
import { GuardRedirectService } from 'src/engine/core-modules/guard-redirect/services/guard-redirect.service';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
|
||||
@Injectable()
|
||||
export class GoogleOauthGuard extends AuthGuard('google') {
|
||||
constructor(
|
||||
private readonly guardRedirectService: GuardRedirectService,
|
||||
private readonly environmentService: EnvironmentService,
|
||||
@InjectRepository(Workspace, 'core')
|
||||
private readonly workspaceRepository: Repository<Workspace>,
|
||||
) {
|
||||
@ -53,9 +51,9 @@ export class GoogleOauthGuard extends AuthGuard('google') {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
workspace ?? {
|
||||
subdomain: this.environmentService.get('DEFAULT_SUBDOMAIN'),
|
||||
},
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
workspace,
|
||||
),
|
||||
);
|
||||
|
||||
return false;
|
||||
|
||||
@ -28,9 +28,11 @@ export class GoogleProviderEnabledGuard implements CanActivate {
|
||||
|
||||
return true;
|
||||
} catch (err) {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(context, err, {
|
||||
subdomain: this.guardRedirectService.getSubdomainFromContext(context),
|
||||
});
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromContext(context),
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -57,9 +57,7 @@ export class MicrosoftAPIsOauthExchangeCodeForTokenGuard extends AuthGuard(
|
||||
AuthExceptionCode.INSUFFICIENT_SCOPES,
|
||||
)
|
||||
: error,
|
||||
{
|
||||
subdomain: this.guardRedirectService.getSubdomainFromContext(context),
|
||||
},
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromContext(context),
|
||||
);
|
||||
|
||||
return false;
|
||||
|
||||
@ -72,9 +72,9 @@ export class MicrosoftAPIsOauthRequestCodeGuard extends AuthGuard(
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
workspace ?? {
|
||||
subdomain: this.environmentService.get('DEFAULT_SUBDOMAIN'),
|
||||
},
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
workspace,
|
||||
),
|
||||
);
|
||||
|
||||
return false;
|
||||
|
||||
@ -5,14 +5,12 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { GuardRedirectService } from 'src/engine/core-modules/guard-redirect/services/guard-redirect.service';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
|
||||
@Injectable()
|
||||
export class MicrosoftOAuthGuard extends AuthGuard('microsoft') {
|
||||
constructor(
|
||||
private readonly guardRedirectService: GuardRedirectService,
|
||||
private readonly environmentService: EnvironmentService,
|
||||
@InjectRepository(Workspace, 'core')
|
||||
private readonly workspaceRepository: Repository<Workspace>,
|
||||
) {
|
||||
@ -41,9 +39,9 @@ export class MicrosoftOAuthGuard extends AuthGuard('microsoft') {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
workspace ?? {
|
||||
subdomain: this.environmentService.get('DEFAULT_SUBDOMAIN'),
|
||||
},
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
workspace,
|
||||
),
|
||||
);
|
||||
|
||||
return false;
|
||||
|
||||
@ -28,9 +28,11 @@ export class MicrosoftProviderEnabledGuard implements CanActivate {
|
||||
|
||||
return true;
|
||||
} catch (err) {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(context, err, {
|
||||
subdomain: this.guardRedirectService.getSubdomainFromContext(context),
|
||||
});
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromContext(context),
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -12,7 +12,6 @@ import {
|
||||
import { OIDCAuthStrategy } from 'src/engine/core-modules/auth/strategies/oidc.auth.strategy';
|
||||
import { SSOService } from 'src/engine/core-modules/sso/services/sso.service';
|
||||
import { GuardRedirectService } from 'src/engine/core-modules/guard-redirect/services/guard-redirect.service';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { SSOConfiguration } from 'src/engine/core-modules/sso/types/SSOConfigurations.type';
|
||||
import { WorkspaceSSOIdentityProvider } from 'src/engine/core-modules/sso/workspace-sso-identity-provider.entity';
|
||||
|
||||
@ -21,12 +20,13 @@ export class OIDCAuthGuard extends AuthGuard('openidconnect') {
|
||||
constructor(
|
||||
private readonly sSOService: SSOService,
|
||||
private readonly guardRedirectService: GuardRedirectService,
|
||||
private readonly environmentService: EnvironmentService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
private getIdentityProviderId(request: any): string {
|
||||
private getStateByRequest(request: any): {
|
||||
identityProviderId: string;
|
||||
} {
|
||||
if (request.params.identityProviderId) {
|
||||
return request.params.identityProviderId;
|
||||
}
|
||||
@ -39,24 +39,27 @@ export class OIDCAuthGuard extends AuthGuard('openidconnect') {
|
||||
) {
|
||||
const state = JSON.parse(request.query.state);
|
||||
|
||||
return state.identityProviderId;
|
||||
return {
|
||||
identityProviderId: state.identityProviderId,
|
||||
};
|
||||
}
|
||||
|
||||
throw new Error('Invalid OIDC identity provider params');
|
||||
}
|
||||
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const request = context.switchToHttp().getRequest<Request>();
|
||||
|
||||
let identityProvider:
|
||||
| (SSOConfiguration & WorkspaceSSOIdentityProvider)
|
||||
| null = null;
|
||||
|
||||
try {
|
||||
const identityProviderId = this.getIdentityProviderId(request);
|
||||
const state = this.getStateByRequest(request);
|
||||
|
||||
identityProvider =
|
||||
await this.sSOService.findSSOIdentityProviderById(identityProviderId);
|
||||
identityProvider = await this.sSOService.findSSOIdentityProviderById(
|
||||
state.identityProviderId,
|
||||
);
|
||||
|
||||
if (!identityProvider) {
|
||||
throw new AuthException(
|
||||
@ -77,9 +80,9 @@ export class OIDCAuthGuard extends AuthGuard('openidconnect') {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
identityProvider?.workspace ?? {
|
||||
subdomain: this.environmentService.get('DEFAULT_SUBDOMAIN'),
|
||||
},
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
identityProvider?.workspace,
|
||||
),
|
||||
);
|
||||
|
||||
return false;
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
import { ExecutionContext, Injectable } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
|
||||
import { Request } from 'express';
|
||||
|
||||
import {
|
||||
AuthException,
|
||||
AuthExceptionCode,
|
||||
@ -10,22 +12,34 @@ import {
|
||||
import { SamlAuthStrategy } from 'src/engine/core-modules/auth/strategies/saml.auth.strategy';
|
||||
import { SSOService } from 'src/engine/core-modules/sso/services/sso.service';
|
||||
import { GuardRedirectService } from 'src/engine/core-modules/guard-redirect/services/guard-redirect.service';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { SSOConfiguration } from 'src/engine/core-modules/sso/types/SSOConfigurations.type';
|
||||
import { WorkspaceSSOIdentityProvider } from 'src/engine/core-modules/sso/workspace-sso-identity-provider.entity';
|
||||
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
|
||||
|
||||
@Injectable()
|
||||
export class SAMLAuthGuard extends AuthGuard('saml') {
|
||||
constructor(
|
||||
private readonly sSOService: SSOService,
|
||||
private readonly guardRedirectService: GuardRedirectService,
|
||||
private readonly environmentService: EnvironmentService,
|
||||
private readonly exceptionHandlerService: ExceptionHandlerService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
private getRelayStateByRequest(request: Request) {
|
||||
try {
|
||||
const relayStateRaw = request.body.RelayState || request.query.RelayState;
|
||||
|
||||
if (relayStateRaw) {
|
||||
return JSON.parse(relayStateRaw);
|
||||
}
|
||||
} catch (error) {
|
||||
this.exceptionHandlerService.captureExceptions(error);
|
||||
}
|
||||
}
|
||||
|
||||
async canActivate(context: ExecutionContext) {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const request = context.switchToHttp().getRequest<Request>();
|
||||
|
||||
let identityProvider:
|
||||
| (SSOConfiguration & WorkspaceSSOIdentityProvider)
|
||||
@ -49,9 +63,9 @@ export class SAMLAuthGuard extends AuthGuard('saml') {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
identityProvider?.workspace ?? {
|
||||
subdomain: this.environmentService.get('DEFAULT_SUBDOMAIN'),
|
||||
},
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
identityProvider?.workspace,
|
||||
),
|
||||
);
|
||||
|
||||
return false;
|
||||
|
||||
@ -455,15 +455,15 @@ export class AuthService {
|
||||
|
||||
computeRedirectURI({
|
||||
loginToken,
|
||||
subdomain,
|
||||
workspace,
|
||||
billingCheckoutSessionState,
|
||||
}: {
|
||||
loginToken: string;
|
||||
subdomain: string;
|
||||
workspace: Pick<Workspace, 'subdomain' | 'hostname'>;
|
||||
billingCheckoutSessionState?: string;
|
||||
}) {
|
||||
const url = this.domainManagerService.buildWorkspaceURL({
|
||||
subdomain,
|
||||
workspace,
|
||||
pathname: '/verify',
|
||||
searchParams: {
|
||||
loginToken,
|
||||
|
||||
@ -50,7 +50,6 @@ export class OIDCAuthStrategy extends PassportStrategy(
|
||||
...options,
|
||||
state: JSON.stringify({
|
||||
identityProviderId: req.params.identityProviderId,
|
||||
...(req.query.forceSubdomainUrl ? { forceSubdomainUrl: true } : {}),
|
||||
...(req.query.workspaceInviteHash
|
||||
? { workspaceInviteHash: req.query.workspaceInviteHash }
|
||||
: {}),
|
||||
|
||||
@ -2,4 +2,5 @@
|
||||
|
||||
export enum BillingEntitlementKey {
|
||||
SSO = 'SSO',
|
||||
CUSTOM_DOMAIN = 'CUSTOM_DOMAIN',
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ export class BillingPortalWorkspaceService {
|
||||
requirePaymentMethod,
|
||||
}: BillingPortalCheckoutSessionParameters): Promise<string> {
|
||||
const frontBaseUrl = this.domainManagerService.buildWorkspaceURL({
|
||||
subdomain: workspace.subdomain,
|
||||
workspace,
|
||||
});
|
||||
const cancelUrl = frontBaseUrl.toString();
|
||||
|
||||
@ -118,7 +118,7 @@ export class BillingPortalWorkspaceService {
|
||||
}
|
||||
|
||||
const frontBaseUrl = this.domainManagerService.buildWorkspaceURL({
|
||||
subdomain: workspace.subdomain,
|
||||
workspace,
|
||||
});
|
||||
|
||||
if (returnUrlPath) {
|
||||
|
||||
@ -41,6 +41,12 @@ describe('transformStripeEntitlementUpdatedEventToDatabaseEntitlement', () => {
|
||||
value: true,
|
||||
stripeCustomerId: 'cus_123',
|
||||
},
|
||||
{
|
||||
key: BillingEntitlementKey.CUSTOM_DOMAIN,
|
||||
stripeCustomerId: 'cus_123',
|
||||
value: false,
|
||||
workspaceId: 'workspaceId',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
@ -79,6 +85,12 @@ describe('transformStripeEntitlementUpdatedEventToDatabaseEntitlement', () => {
|
||||
value: false,
|
||||
stripeCustomerId: 'cus_123',
|
||||
},
|
||||
{
|
||||
key: 'CUSTOM_DOMAIN',
|
||||
stripeCustomerId: 'cus_123',
|
||||
value: false,
|
||||
workspaceId: 'workspaceId',
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,6 +9,53 @@ import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { DomainManagerService } from './domain-manager.service';
|
||||
|
||||
describe('DomainManagerService', () => {
|
||||
describe('getworkspaceUrls', () => {
|
||||
it('should return a URL containing the correct hostname if hostname is provided', () => {
|
||||
jest
|
||||
.spyOn(environmentService, 'get')
|
||||
.mockImplementation((key: string) => {
|
||||
const env = {
|
||||
FRONT_PROTOCOL: 'https',
|
||||
FRONT_DOMAIN: 'example.com',
|
||||
};
|
||||
|
||||
return env[key];
|
||||
});
|
||||
|
||||
const result = domainManagerService.getworkspaceUrls({
|
||||
subdomain: 'subdomain',
|
||||
hostname: 'custom-host.com',
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
customUrl: 'https://custom-host.com/',
|
||||
subdomainUrl: 'https://subdomain.example.com/',
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a URL containing the correct subdomain if hostname is not provided but subdomain is', () => {
|
||||
jest
|
||||
.spyOn(environmentService, 'get')
|
||||
.mockImplementation((key: string) => {
|
||||
const env = {
|
||||
FRONT_PROTOCOL: 'https',
|
||||
FRONT_DOMAIN: 'example.com',
|
||||
};
|
||||
|
||||
return env[key];
|
||||
});
|
||||
|
||||
const result = domainManagerService.getworkspaceUrls({
|
||||
subdomain: 'subdomain',
|
||||
hostname: undefined,
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
customUrl: undefined,
|
||||
subdomainUrl: 'https://subdomain.example.com/',
|
||||
});
|
||||
});
|
||||
});
|
||||
let domainManagerService: DomainManagerService;
|
||||
let environmentService: EnvironmentService;
|
||||
|
||||
@ -106,7 +153,10 @@ describe('DomainManagerService', () => {
|
||||
});
|
||||
|
||||
const result = domainManagerService.buildWorkspaceURL({
|
||||
subdomain: 'test',
|
||||
workspace: {
|
||||
subdomain: 'test',
|
||||
hostname: undefined,
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.toString()).toBe('https://test.example.com/');
|
||||
@ -125,7 +175,10 @@ describe('DomainManagerService', () => {
|
||||
});
|
||||
|
||||
const result = domainManagerService.buildWorkspaceURL({
|
||||
subdomain: 'subdomain',
|
||||
workspace: {
|
||||
subdomain: 'test',
|
||||
hostname: undefined,
|
||||
},
|
||||
pathname: '/path/to/resource',
|
||||
});
|
||||
|
||||
@ -145,8 +198,10 @@ describe('DomainManagerService', () => {
|
||||
});
|
||||
|
||||
const result = domainManagerService.buildWorkspaceURL({
|
||||
subdomain: 'subdomain',
|
||||
|
||||
workspace: {
|
||||
subdomain: 'test',
|
||||
hostname: undefined,
|
||||
},
|
||||
searchParams: {
|
||||
foo: 'bar',
|
||||
baz: 123,
|
||||
|
||||
@ -74,33 +74,31 @@ export class DomainManagerService {
|
||||
buildEmailVerificationURL({
|
||||
emailVerificationToken,
|
||||
email,
|
||||
subdomain,
|
||||
workspace,
|
||||
}: {
|
||||
emailVerificationToken: string;
|
||||
email: string;
|
||||
subdomain: string;
|
||||
workspace: Pick<Workspace, 'subdomain' | 'hostname'>;
|
||||
}) {
|
||||
return this.buildWorkspaceURL({
|
||||
subdomain,
|
||||
workspace,
|
||||
pathname: 'verify-email',
|
||||
searchParams: { emailVerificationToken, email },
|
||||
});
|
||||
}
|
||||
|
||||
buildWorkspaceURL({
|
||||
subdomain,
|
||||
workspace,
|
||||
pathname,
|
||||
searchParams,
|
||||
}: {
|
||||
subdomain: string;
|
||||
workspace: Pick<Workspace, 'subdomain' | 'hostname'>;
|
||||
pathname?: string;
|
||||
searchParams?: Record<string, string | number>;
|
||||
}) {
|
||||
const url = this.getFrontUrl();
|
||||
const workspaceUrls = this.getworkspaceUrls(workspace);
|
||||
|
||||
if (this.environmentService.get('IS_MULTIWORKSPACE_ENABLED')) {
|
||||
url.hostname = `${subdomain}.${url.hostname}`;
|
||||
}
|
||||
const url = new URL(workspaceUrls.customUrl ?? workspaceUrls.subdomainUrl);
|
||||
|
||||
if (pathname) {
|
||||
url.pathname = pathname;
|
||||
@ -117,21 +115,6 @@ export class DomainManagerService {
|
||||
return url;
|
||||
}
|
||||
|
||||
// @Deprecated
|
||||
getWorkspaceSubdomainFromUrl = (url: string) => {
|
||||
const { hostname: originHostname } = new URL(url);
|
||||
|
||||
if (!originHostname.endsWith(this.getFrontUrl().hostname)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const frontDomain = this.getFrontUrl().hostname;
|
||||
|
||||
const subdomain = originHostname.replace(`.${frontDomain}`, '');
|
||||
|
||||
return this.isDefaultSubdomain(subdomain) ? null : subdomain;
|
||||
};
|
||||
|
||||
getSubdomainAndHostnameFromUrl = (url: string) => {
|
||||
const { hostname: originHostname } = new URL(url);
|
||||
|
||||
@ -162,9 +145,12 @@ export class DomainManagerService {
|
||||
return subdomain === this.environmentService.get('DEFAULT_SUBDOMAIN');
|
||||
}
|
||||
|
||||
computeRedirectErrorUrl(errorMessage: string, subdomain: string) {
|
||||
computeRedirectErrorUrl(
|
||||
errorMessage: string,
|
||||
workspace: Pick<Workspace, 'subdomain' | 'hostname'>,
|
||||
) {
|
||||
const url = this.buildWorkspaceURL({
|
||||
subdomain: subdomain,
|
||||
workspace,
|
||||
pathname: '/verify',
|
||||
searchParams: { errorMessage },
|
||||
});
|
||||
@ -352,7 +338,7 @@ export class DomainManagerService {
|
||||
await this.deleteCustomHostname(fromCustomHostname.id);
|
||||
}
|
||||
|
||||
return await this.registerCustomHostname(toHostname);
|
||||
return this.registerCustomHostname(toHostname);
|
||||
}
|
||||
|
||||
async deleteCustomHostnameByHostnameSilently(hostname: string) {
|
||||
@ -378,4 +364,32 @@ export class DomainManagerService {
|
||||
zone_id: this.environmentService.get('CLOUDFLARE_ZONE_ID'),
|
||||
});
|
||||
}
|
||||
|
||||
private getCustomWorkspaceEndpoint(hostname: string) {
|
||||
const url = this.getFrontUrl();
|
||||
|
||||
url.hostname = hostname;
|
||||
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
private getTwentyWorkspaceEndpoint(subdomain: string) {
|
||||
const url = this.getFrontUrl();
|
||||
|
||||
url.hostname = `${subdomain}.${url.hostname}`;
|
||||
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
getworkspaceUrls({
|
||||
subdomain,
|
||||
hostname,
|
||||
}: Pick<Workspace, 'subdomain' | 'hostname'>) {
|
||||
return {
|
||||
customUrl: hostname
|
||||
? this.getCustomWorkspaceEndpoint(hostname)
|
||||
: undefined,
|
||||
subdomainUrl: this.getTwentyWorkspaceEndpoint(subdomain),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ export class EmailVerificationResolver {
|
||||
|
||||
return await this.emailVerificationService.resendEmailVerificationToken(
|
||||
resendEmailVerificationTokenInput.email,
|
||||
workspace.subdomain,
|
||||
workspace,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import {
|
||||
import { EmailService } from 'src/engine/core-modules/email/email.service';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { UserService } from 'src/engine/core-modules/user/services/user.service';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
|
||||
@Injectable()
|
||||
// eslint-disable-next-line @nx/workspace-inject-workspace-repository
|
||||
@ -38,7 +39,7 @@ export class EmailVerificationService {
|
||||
async sendVerificationEmail(
|
||||
userId: string,
|
||||
email: string,
|
||||
subdomain: string,
|
||||
workspace: Pick<Workspace, 'subdomain' | 'hostname'>,
|
||||
) {
|
||||
if (!this.environmentService.get('IS_EMAIL_VERIFICATION_REQUIRED')) {
|
||||
return { success: false };
|
||||
@ -51,7 +52,7 @@ export class EmailVerificationService {
|
||||
this.domainManagerService.buildEmailVerificationURL({
|
||||
emailVerificationToken,
|
||||
email,
|
||||
subdomain,
|
||||
workspace,
|
||||
});
|
||||
|
||||
const emailData = {
|
||||
@ -80,7 +81,10 @@ export class EmailVerificationService {
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
async resendEmailVerificationToken(email: string, subdomain: string) {
|
||||
async resendEmailVerificationToken(
|
||||
email: string,
|
||||
workspace: Pick<Workspace, 'subdomain' | 'hostname'>,
|
||||
) {
|
||||
if (!this.environmentService.get('IS_EMAIL_VERIFICATION_REQUIRED')) {
|
||||
throw new EmailVerificationException(
|
||||
'Email verification token cannot be sent because email verification is not required',
|
||||
@ -121,7 +125,7 @@ export class EmailVerificationService {
|
||||
await this.appTokenRepository.delete(existingToken.id);
|
||||
}
|
||||
|
||||
await this.sendVerificationEmail(user.id, email, subdomain);
|
||||
await this.sendVerificationEmail(user.id, email, workspace);
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
import { ExecutionContext, Injectable } from '@nestjs/common';
|
||||
|
||||
import { Request } from 'express';
|
||||
|
||||
import { DomainManagerService } from 'src/engine/core-modules/domain-manager/services/domain-manager.service';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { CustomException } from 'src/utils/custom-exception';
|
||||
import { AuthException } from 'src/engine/core-modules/auth/auth.exception';
|
||||
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
|
||||
@Injectable()
|
||||
export class GuardRedirectService {
|
||||
@ -17,7 +20,7 @@ export class GuardRedirectService {
|
||||
dispatchErrorFromGuard(
|
||||
context: ExecutionContext,
|
||||
error: Error | CustomException,
|
||||
workspace: { id?: string; subdomain: string },
|
||||
workspace: { id?: string; subdomain: string; hostname?: string },
|
||||
) {
|
||||
if ('contextType' in context && context.contextType === 'graphql') {
|
||||
throw error;
|
||||
@ -29,15 +32,36 @@ export class GuardRedirectService {
|
||||
.redirect(this.getRedirectErrorUrlAndCaptureExceptions(error, workspace));
|
||||
}
|
||||
|
||||
getSubdomainFromContext(context: ExecutionContext) {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
getSubdomainAndHostnameFromWorkspace(
|
||||
workspace?: Pick<Workspace, 'subdomain' | 'hostname'> | null,
|
||||
) {
|
||||
if (!workspace) {
|
||||
return {
|
||||
subdomain: this.environmentService.get('DEFAULT_SUBDOMAIN'),
|
||||
};
|
||||
}
|
||||
|
||||
const subdomainFromUrl =
|
||||
this.domainManagerService.getWorkspaceSubdomainFromUrl(
|
||||
request.headers.referer,
|
||||
);
|
||||
return workspace;
|
||||
}
|
||||
|
||||
return subdomainFromUrl ?? this.environmentService.get('DEFAULT_SUBDOMAIN');
|
||||
getSubdomainAndHostnameFromContext(context: ExecutionContext): {
|
||||
subdomain: string;
|
||||
hostname?: string;
|
||||
} {
|
||||
const request = context.switchToHttp().getRequest<Request>();
|
||||
|
||||
const subdomainAndHostnameFromReferer = request.headers.referer
|
||||
? this.domainManagerService.getSubdomainAndHostnameFromUrl(
|
||||
request.headers.referer,
|
||||
)
|
||||
: null;
|
||||
|
||||
return {
|
||||
subdomain:
|
||||
subdomainAndHostnameFromReferer?.subdomain ??
|
||||
this.environmentService.get('DEFAULT_SUBDOMAIN'),
|
||||
hostname: subdomainAndHostnameFromReferer?.hostname,
|
||||
};
|
||||
}
|
||||
|
||||
private captureException(err: Error | CustomException, workspaceId?: string) {
|
||||
@ -52,13 +76,13 @@ export class GuardRedirectService {
|
||||
|
||||
getRedirectErrorUrlAndCaptureExceptions(
|
||||
err: Error | CustomException,
|
||||
workspace: { id?: string; subdomain: string },
|
||||
workspace: { id?: string; subdomain: string; hostname?: string },
|
||||
) {
|
||||
this.captureException(err, workspace.id);
|
||||
|
||||
return this.domainManagerService.computeRedirectErrorUrl(
|
||||
err instanceof AuthException ? err.message : 'Unknown error',
|
||||
workspace.subdomain,
|
||||
workspace,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
import { Field, InputType } from '@nestjs/graphql';
|
||||
|
||||
import { IsOptional, IsString } from 'class-validator';
|
||||
import { IsOptional, IsBoolean, IsString } from 'class-validator';
|
||||
|
||||
@InputType()
|
||||
export class GetAuthorizationUrlInput {
|
||||
|
||||
@ -15,6 +15,7 @@ import { DataSourceModule } from 'src/engine/metadata-modules/data-source/data-s
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module';
|
||||
import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module';
|
||||
import { DomainManagerModule } from 'src/engine/core-modules/domain-manager/domain-manager.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@ -29,6 +30,7 @@ import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/works
|
||||
DataSourceModule,
|
||||
WorkspaceDataSourceModule,
|
||||
WorkspaceInvitationModule,
|
||||
DomainManagerModule,
|
||||
TwentyORMModule,
|
||||
],
|
||||
services: [UserWorkspaceService],
|
||||
|
||||
@ -24,6 +24,7 @@ import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.
|
||||
import { WorkspaceEventEmitter } from 'src/engine/workspace-event-emitter/workspace-event-emitter';
|
||||
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
||||
import { assert } from 'src/utils/assert';
|
||||
import { DomainManagerService } from 'src/engine/core-modules/domain-manager/services/domain-manager.service';
|
||||
|
||||
export class UserWorkspaceService extends TypeOrmQueryService<UserWorkspace> {
|
||||
constructor(
|
||||
@ -37,6 +38,7 @@ export class UserWorkspaceService extends TypeOrmQueryService<UserWorkspace> {
|
||||
private readonly typeORMService: TypeORMService,
|
||||
private readonly workspaceInvitationService: WorkspaceInvitationService,
|
||||
private readonly workspaceEventEmitter: WorkspaceEventEmitter,
|
||||
private readonly domainManagerService: DomainManagerService,
|
||||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
||||
) {
|
||||
super(userWorkspaceRepository);
|
||||
@ -179,7 +181,9 @@ export class UserWorkspaceService extends TypeOrmQueryService<UserWorkspace> {
|
||||
return user.workspaces.map<AvailableWorkspaceOutput>((userWorkspace) => ({
|
||||
id: userWorkspace.workspaceId,
|
||||
displayName: userWorkspace.workspace.displayName,
|
||||
subdomain: userWorkspace.workspace.subdomain,
|
||||
workspaceUrls: this.domainManagerService.getworkspaceUrls(
|
||||
userWorkspace.workspace,
|
||||
),
|
||||
logo: userWorkspace.workspace.logo,
|
||||
sso: userWorkspace.workspace.workspaceSSOIdentityProviders.reduce(
|
||||
(acc, identityProvider) =>
|
||||
|
||||
@ -19,7 +19,6 @@ import { KeyValuePair } from 'src/engine/core-modules/key-value-pair/key-value-p
|
||||
import { OnboardingStatus } from 'src/engine/core-modules/onboarding/enums/onboarding-status.enum';
|
||||
import { UserWorkspace } from 'src/engine/core-modules/user-workspace/user-workspace.entity';
|
||||
import { WorkspaceMember } from 'src/engine/core-modules/user/dtos/workspace-member.dto';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
|
||||
registerEnumType(OnboardingStatus, {
|
||||
name: 'OnboardingStatus',
|
||||
@ -100,7 +99,4 @@ export class User {
|
||||
|
||||
@Field(() => OnboardingStatus, { nullable: true })
|
||||
onboardingStatus: OnboardingStatus;
|
||||
|
||||
@Field(() => Workspace, { nullable: true })
|
||||
currentWorkspace: Relation<Workspace>;
|
||||
}
|
||||
|
||||
@ -81,22 +81,7 @@ export class UserResolver {
|
||||
) {}
|
||||
|
||||
@Query(() => User)
|
||||
async currentUser(
|
||||
@AuthUser() { id: userId }: User,
|
||||
@OriginHeader() origin: string,
|
||||
): Promise<User> {
|
||||
const workspace =
|
||||
await this.domainManagerService.getWorkspaceByOriginOrDefaultWorkspace(
|
||||
origin,
|
||||
);
|
||||
|
||||
workspaceValidator.assertIsDefinedOrThrow(workspace);
|
||||
|
||||
await this.userService.hasUserAccessToWorkspaceOrThrow(
|
||||
userId,
|
||||
workspace.id,
|
||||
);
|
||||
|
||||
async currentUser(@AuthUser() { id: userId }: User): Promise<User> {
|
||||
const user = await this.userRepository.findOne({
|
||||
where: {
|
||||
id: userId,
|
||||
@ -109,7 +94,7 @@ export class UserResolver {
|
||||
new AuthException('User not found', AuthExceptionCode.USER_NOT_FOUND),
|
||||
);
|
||||
|
||||
return { ...user, currentWorkspace: workspace };
|
||||
return user;
|
||||
}
|
||||
|
||||
@ResolveField(() => GraphQLJSONObject)
|
||||
@ -314,4 +299,9 @@ export class UserResolver {
|
||||
|
||||
return this.onboardingService.getOnboardingStatus(user, workspace);
|
||||
}
|
||||
|
||||
@ResolveField(() => Workspace)
|
||||
async currentWorkspace(@AuthWorkspace() workspace: Workspace) {
|
||||
return workspace;
|
||||
}
|
||||
}
|
||||
|
||||
@ -279,7 +279,7 @@ export class WorkspaceInvitationService {
|
||||
for (const invitation of invitationsPr) {
|
||||
if (invitation.status === 'fulfilled') {
|
||||
const link = this.domainManagerService.buildWorkspaceURL({
|
||||
subdomain: workspace.subdomain,
|
||||
workspace,
|
||||
pathname: `invite/${workspace?.inviteHash}`,
|
||||
searchParams: invitation.value.isPersonalInvitation
|
||||
? {
|
||||
|
||||
@ -5,6 +5,7 @@ import {
|
||||
IdentityProviderType,
|
||||
SSOIdentityProviderStatus,
|
||||
} from 'src/engine/core-modules/sso/workspace-sso-identity-provider.entity';
|
||||
import { workspaceUrls } from 'src/engine/core-modules/workspace/dtos/workspace-endpoints.dto';
|
||||
|
||||
@ObjectType()
|
||||
export class SSOIdentityProvider {
|
||||
@ -56,9 +57,6 @@ export class PublicWorkspaceDataOutput {
|
||||
@Field(() => String, { nullable: true })
|
||||
displayName: Workspace['displayName'];
|
||||
|
||||
@Field(() => String)
|
||||
subdomain: Workspace['subdomain'];
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
hostname: Workspace['hostname'];
|
||||
@Field(() => workspaceUrls)
|
||||
workspaceUrls: workspaceUrls;
|
||||
}
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
import { ObjectType, Field } from '@nestjs/graphql';
|
||||
|
||||
@ObjectType()
|
||||
export class workspaceUrls {
|
||||
@Field(() => String, { nullable: true })
|
||||
customUrl?: string;
|
||||
|
||||
@Field(() => String)
|
||||
subdomainUrl: string;
|
||||
}
|
||||
@ -1,9 +1,11 @@
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
import { workspaceUrls } from 'src/engine/core-modules/workspace/dtos/workspace-endpoints.dto';
|
||||
|
||||
@ObjectType()
|
||||
export class WorkspaceSubdomainAndId {
|
||||
@Field()
|
||||
subdomain: string;
|
||||
export class workspaceUrlsAndId {
|
||||
@Field(() => workspaceUrls)
|
||||
workspaceUrls: workspaceUrls;
|
||||
|
||||
@Field()
|
||||
id: string;
|
||||
|
||||
@ -15,6 +15,7 @@ import { User } from 'src/engine/core-modules/user/user.entity';
|
||||
import { WorkspaceInvitationService } from 'src/engine/core-modules/workspace-invitation/services/workspace-invitation.service';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { WorkspaceManagerService } from 'src/engine/workspace-manager/workspace-manager.service';
|
||||
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
|
||||
|
||||
import { WorkspaceService } from './workspace.service';
|
||||
|
||||
@ -81,6 +82,10 @@ describe('WorkspaceService', () => {
|
||||
provide: FeatureFlagService,
|
||||
useValue: {},
|
||||
},
|
||||
{
|
||||
provide: ExceptionHandlerService,
|
||||
useValue: {},
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import assert from 'assert';
|
||||
|
||||
import { TypeOrmQueryService } from '@ptc-org/nestjs-query-typeorm';
|
||||
import { WorkspaceActivationStatus, isDefined } from 'twenty-shared';
|
||||
import { isDefined, WorkspaceActivationStatus } from 'twenty-shared';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { BillingSubscriptionService } from 'src/engine/core-modules/billing/services/billing-subscription.service';
|
||||
@ -24,10 +24,14 @@ import {
|
||||
import { workspaceValidator } from 'src/engine/core-modules/workspace/workspace.validate';
|
||||
import { WorkspaceManagerService } from 'src/engine/workspace-manager/workspace-manager.service';
|
||||
import { DEFAULT_FEATURE_FLAGS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/default-feature-flags';
|
||||
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
|
||||
import { BillingEntitlementKey } from 'src/engine/core-modules/billing/enums/billing-entitlement-key.enum';
|
||||
|
||||
@Injectable()
|
||||
// eslint-disable-next-line @nx/workspace-inject-workspace-repository
|
||||
export class WorkspaceService extends TypeOrmQueryService<Workspace> {
|
||||
private readonly featureLookUpKey = BillingEntitlementKey.CUSTOM_DOMAIN;
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Workspace, 'core')
|
||||
private readonly workspaceRepository: Repository<Workspace>,
|
||||
@ -42,10 +46,26 @@ export class WorkspaceService extends TypeOrmQueryService<Workspace> {
|
||||
private readonly userWorkspaceService: UserWorkspaceService,
|
||||
private readonly environmentService: EnvironmentService,
|
||||
private readonly domainManagerService: DomainManagerService,
|
||||
private readonly exceptionHandlerService: ExceptionHandlerService,
|
||||
) {
|
||||
super(workspaceRepository);
|
||||
}
|
||||
|
||||
private async isCustomDomainEnabled(workspaceId: string) {
|
||||
const isCustomDomainBillingEnabled =
|
||||
await this.billingService.hasEntitlement(
|
||||
workspaceId,
|
||||
this.featureLookUpKey,
|
||||
);
|
||||
|
||||
if (!isCustomDomainBillingEnabled) {
|
||||
throw new WorkspaceException(
|
||||
`No entitlement found for this workspace`,
|
||||
WorkspaceExceptionCode.WORKSPACE_CUSTOM_DOMAIN_DISABLED,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async validateSubdomainUpdate(newSubdomain: string) {
|
||||
const subdomainAvailable = await this.isSubdomainAvailable(newSubdomain);
|
||||
|
||||
@ -61,6 +81,8 @@ export class WorkspaceService extends TypeOrmQueryService<Workspace> {
|
||||
}
|
||||
|
||||
private async setCustomDomain(workspace: Workspace, hostname: string) {
|
||||
await this.isCustomDomainEnabled(workspace.id);
|
||||
|
||||
const existingWorkspace = await this.workspaceRepository.findOne({
|
||||
where: { hostname },
|
||||
});
|
||||
@ -126,10 +148,11 @@ export class WorkspaceService extends TypeOrmQueryService<Workspace> {
|
||||
if (payload.hostname && customDomainRegistered) {
|
||||
this.domainManagerService
|
||||
.deleteCustomHostnameByHostnameSilently(payload.hostname)
|
||||
.catch(() => {
|
||||
// send to sentry
|
||||
.catch((err) => {
|
||||
this.exceptionHandlerService.captureExceptions([err]);
|
||||
});
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -11,4 +11,5 @@ export enum WorkspaceExceptionCode {
|
||||
SUBDOMAIN_ALREADY_TAKEN = 'SUBDOMAIN_ALREADY_TAKEN',
|
||||
DOMAIN_ALREADY_TAKEN = 'DOMAIN_ALREADY_TAKEN',
|
||||
WORKSPACE_NOT_FOUND = 'WORKSPACE_NOT_FOUND',
|
||||
WORKSPACE_CUSTOM_DOMAIN_DISABLED = 'WORKSPACE_CUSTOM_DOMAIN_DISABLED',
|
||||
}
|
||||
|
||||
@ -17,7 +17,6 @@ import { FileFolder } from 'src/engine/core-modules/file/interfaces/file-folder.
|
||||
|
||||
import { BillingSubscription } from 'src/engine/core-modules/billing/entities/billing-subscription.entity';
|
||||
import { BillingSubscriptionService } from 'src/engine/core-modules/billing/services/billing-subscription.service';
|
||||
import { CustomHostnameDetails } from 'src/engine/core-modules/domain-manager/dtos/custom-hostname-details';
|
||||
import { DomainManagerService } from 'src/engine/core-modules/domain-manager/services/domain-manager.service';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
|
||||
@ -44,6 +43,8 @@ import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
||||
import { GraphqlValidationExceptionFilter } from 'src/filters/graphql-validation-exception.filter';
|
||||
import { assert } from 'src/utils/assert';
|
||||
import { streamToBuffer } from 'src/utils/stream-to-buffer';
|
||||
import { CustomHostnameDetails } from 'src/engine/core-modules/domain-manager/dtos/custom-hostname-details';
|
||||
import { workspaceUrls } from 'src/engine/core-modules/workspace/dtos/workspace-endpoints.dto';
|
||||
|
||||
import { Workspace } from './workspace.entity';
|
||||
|
||||
@ -214,6 +215,11 @@ export class WorkspaceResolver {
|
||||
return isDefined(this.environmentService.get('ENTERPRISE_KEY'));
|
||||
}
|
||||
|
||||
@ResolveField(() => workspaceUrls)
|
||||
workspaceUrls(@Parent() workspace: Workspace) {
|
||||
return this.domainManagerService.getworkspaceUrls(workspace);
|
||||
}
|
||||
|
||||
@Query(() => CustomHostnameDetails, { nullable: true })
|
||||
@UseGuards(WorkspaceAuthGuard)
|
||||
async getHostnameDetails(
|
||||
@ -225,7 +231,7 @@ export class WorkspaceResolver {
|
||||
}
|
||||
|
||||
@Query(() => PublicWorkspaceDataOutput)
|
||||
async getPublicWorkspaceDataBySubdomain(
|
||||
async getPublicWorkspaceDataByDomain(
|
||||
@OriginHeader() origin: string,
|
||||
): Promise<PublicWorkspaceDataOutput | undefined> {
|
||||
try {
|
||||
@ -262,8 +268,7 @@ export class WorkspaceResolver {
|
||||
id: workspace.id,
|
||||
logo: workspaceLogoWithToken,
|
||||
displayName: workspace.displayName,
|
||||
subdomain: workspace.subdomain,
|
||||
hostname: workspace.hostname,
|
||||
workspaceUrls: this.domainManagerService.getworkspaceUrls(workspace),
|
||||
authProviders: getAuthProvidersByWorkspace({
|
||||
workspace,
|
||||
systemEnabledProviders,
|
||||
|
||||
@ -15,5 +15,5 @@ export const EXCLUDED_MIDDLEWARE_OPERATIONS = [
|
||||
'IntrospectionQuery',
|
||||
'ExchangeAuthorizationCode',
|
||||
'GetAuthorizationUrl',
|
||||
'GetPublicWorkspaceDataBySubdomain',
|
||||
'GetPublicWorkspaceDataByDomain',
|
||||
] as const;
|
||||
|
||||
Reference in New Issue
Block a user