feat(workspace): Add subdomain availability check (#8906)

Implemented a feature to check the availability of subdomains when
updating workspace settings. This includes a new mutation,
`isSubdomainAvailable`, to validate subdomain availability through
GraphQL. The frontend now verifies if a subdomain is available to
prevent duplicates during updates.

---------

Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
Antoine Moreaux
2024-12-06 14:28:30 +01:00
committed by GitHub
parent 5c565345ae
commit 36fb14179b
9 changed files with 139 additions and 42 deletions

View File

@ -10,16 +10,12 @@ export const useLastAuthenticatedWorkspaceDomain = () => {
const setLastAuthenticateWorkspaceDomainWithCookieAttributes = (
params: { workspaceId: string; subdomain: string } | null,
) => {
setLastAuthenticatedWorkspaceDomain(
params
? {
...params,
cookieAttributes: {
domain: `.${domainConfiguration.frontDomain}`,
},
}
: null,
);
setLastAuthenticatedWorkspaceDomain({
...(params ? params : {}),
cookieAttributes: {
domain: `.${domainConfiguration.frontDomain}`,
},
});
};
return {

View File

@ -1,11 +1,16 @@
import { cookieStorageEffect } from '~/utils/recoil-effects';
import { createState } from 'twenty-ui';
export const lastAuthenticatedWorkspaceDomainState = createState<{
subdomain: string;
workspaceId: string;
cookieAttributes?: Cookies.CookieAttributes;
} | null>({
export const lastAuthenticatedWorkspaceDomainState = createState<
| {
subdomain: string;
workspaceId: string;
cookieAttributes?: Cookies.CookieAttributes;
}
| null
// this type is necessary to let the deletion of cookie. Without the domain the cookie is not deleted.
| { cookieAttributes?: Cookies.CookieAttributes }
>({
key: 'lastAuthenticateWorkspaceDomain',
defaultValue: null,
effects: [

View File

@ -41,8 +41,10 @@ export const WorkspaceProviderEffect = () => {
useEffect(() => {
if (
isMultiWorkspaceEnabled &&
isDefined(lastAuthenticatedWorkspaceDomain?.subdomain) &&
isDefaultDomain
isDefaultDomain &&
isDefined(lastAuthenticatedWorkspaceDomain) &&
'subdomain' in lastAuthenticatedWorkspaceDomain &&
isDefined(lastAuthenticatedWorkspaceDomain?.subdomain)
) {
redirectToWorkspaceDomain(lastAuthenticatedWorkspaceDomain.subdomain);
}