Skip to content

Commit 9612a49

Browse files
authored
fix(signinup): several issues (#12698)
- Fixed an issue where you have invitations in your available workspaces for signup. - Corrected the URL display in the browser when hovering over the twenty logo on the sign-in/up form. - The workspace list is now displayed when you are logged into the default domain.
1 parent c9344cf commit 9612a49

File tree

5 files changed

+47
-28
lines changed

5 files changed

+47
-28
lines changed

packages/twenty-front/src/modules/auth/components/Logo.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Avatar } from 'twenty-ui/display';
55
import { UndecoratedLink } from 'twenty-ui/navigation';
66
import { REACT_APP_SERVER_BASE_URL } from '~/config';
77
import { useRedirectToDefaultDomain } from '~/modules/domain-manager/hooks/useRedirectToDefaultDomain';
8-
import { AppPath } from '~/modules/types/AppPath';
8+
import { useReadDefaultDomainFromConfiguration } from '@/domain-manager/hooks/useReadDefaultDomainFromConfiguration';
99

1010
type LogoProps = {
1111
primaryLogo?: string | null;
@@ -59,6 +59,8 @@ export const Logo = ({
5959
const { redirectToDefaultDomain } = useRedirectToDefaultDomain();
6060
const defaultPrimaryLogoUrl = `${window.location.origin}/images/icons/android/android-launchericon-192-192.png`;
6161

62+
const { defaultUrl } = useReadDefaultDomainFromConfiguration();
63+
6264
const primaryLogoUrl = getImageAbsoluteURI({
6365
imageUrl: primaryLogo ?? defaultPrimaryLogoUrl,
6466
baseUrl: REACT_APP_SERVER_BASE_URL,
@@ -77,7 +79,7 @@ export const Logo = ({
7779
<StyledContainer onClick={() => onClick?.()}>
7880
{isUsingDefaultLogo ? (
7981
<UndecoratedLink
80-
to={AppPath.SignInUp}
82+
to={defaultUrl.toString()}
8183
onClick={redirectToDefaultDomain}
8284
>
8385
<StyledPrimaryLogo src={primaryLogoUrl} />

packages/twenty-front/src/modules/auth/sign-in-up/components/internal/SignInUpGlobalScopeFormEffect.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ import {
33
signInUpStepState,
44
} from '@/auth/states/signInUpStepState';
55
import { useEffect } from 'react';
6-
import { useSetRecoilState } from 'recoil';
6+
import { useRecoilValue, useSetRecoilState } from 'recoil';
77
import { isDefined } from 'twenty-shared/utils';
88
import { useAuth } from '@/auth/hooks/useAuth';
99
import { useSearchParams } from 'react-router-dom';
10+
import { availableWorkspacesState } from '@/auth/states/availableWorkspacesState';
11+
import { countAvailableWorkspaces } from '@/auth/utils/availableWorkspacesUtils';
1012

1113
export const SignInUpGlobalScopeFormEffect = () => {
1214
const setSignInUpStep = useSetRecoilState(signInUpStepState);
1315
const [searchParams, setSearchParams] = useSearchParams();
1416
const { setAuthTokens, loadCurrentUser } = useAuth();
17+
const availableWorkspaces = useRecoilValue(availableWorkspacesState);
1518

1619
useEffect(() => {
1720
const tokenPair = searchParams.get('tokenPair');
@@ -20,6 +23,9 @@ export const SignInUpGlobalScopeFormEffect = () => {
2023
searchParams.delete('tokenPair');
2124
setSearchParams(searchParams);
2225
loadCurrentUser();
26+
}
27+
28+
if (countAvailableWorkspaces(availableWorkspaces) > 1) {
2329
setSignInUpStep(SignInUpStep.WorkspaceSelection);
2430
}
2531
}, [
@@ -28,6 +34,7 @@ export const SignInUpGlobalScopeFormEffect = () => {
2834
setSignInUpStep,
2935
loadCurrentUser,
3036
setAuthTokens,
37+
availableWorkspaces,
3138
]);
3239

3340
return <></>;

packages/twenty-front/src/modules/domain-manager/hooks/useReadDefaultDomainFromConfiguration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ export const useReadDefaultDomainFromConfiguration = () => {
1010
? `${domainConfiguration.defaultSubdomain}.${domainConfiguration.frontDomain}`
1111
: domainConfiguration.frontDomain;
1212

13+
const defaultUrl = new URL(window.location.href);
14+
defaultUrl.hostname = defaultDomain;
15+
1316
return {
1417
defaultDomain,
18+
defaultUrl,
1519
};
1620
};

packages/twenty-front/src/pages/auth/SignInUp.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { useSignInUp } from '@/auth/sign-in-up/hooks/useSignInUp';
22
import { useSignInUpForm } from '@/auth/sign-in-up/hooks/useSignInUpForm';
3-
import {
4-
SignInUpStep,
5-
signInUpStepState,
6-
} from '@/auth/states/signInUpStepState';
3+
import { SignInUpStep } from '@/auth/states/signInUpStepState';
74
import { workspacePublicDataState } from '@/auth/states/workspacePublicDataState';
8-
import { useRecoilValue, useSetRecoilState } from 'recoil';
5+
import { useRecoilValue } from 'recoil';
96

107
import { Logo } from '@/auth/components/Logo';
118
import { Title } from '@/auth/components/Title';
@@ -30,6 +27,7 @@ import { isDefined } from 'twenty-shared/utils';
3027
import { AnimatedEaseIn } from 'twenty-ui/utilities';
3128
import { PublicWorkspaceDataOutput } from '~/generated/graphql';
3229
import { SignInUpGlobalScopeFormEffect } from '@/auth/sign-in-up/components/internal/SignInUpGlobalScopeFormEffect';
30+
import { useAuth } from '@/auth/hooks/useAuth';
3331

3432
const StandardContent = ({
3533
workspacePublicData,
@@ -62,7 +60,6 @@ const StandardContent = ({
6260

6361
export const SignInUp = () => {
6462
const { t } = useLingui();
65-
const setSignInUpStep = useSetRecoilState(signInUpStepState);
6663

6764
const { form } = useSignInUpForm();
6865
const { signInUpStep } = useSignInUp(form);
@@ -73,11 +70,14 @@ export const SignInUp = () => {
7370
const isMultiWorkspaceEnabled = useRecoilValue(isMultiWorkspaceEnabledState);
7471
const { workspaceInviteHash, workspace: workspaceFromInviteHash } =
7572
useWorkspaceFromInviteHash();
73+
const { signOut } = useAuth();
7674

7775
const [searchParams] = useSearchParams();
7876

7977
const onClickOnLogo = () => {
80-
setSignInUpStep(SignInUpStep.Init);
78+
if (!isOnAWorkspace && signInUpStep === SignInUpStep.WorkspaceSelection) {
79+
signOut();
80+
}
8181
};
8282

8383
const title = useMemo(() => {

packages/twenty-server/src/engine/core-modules/user-workspace/user-workspace.service.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -406,23 +406,24 @@ export class UserWorkspaceService extends TypeOrmQueryService<UserWorkspace> {
406406
displayName: workspace.displayName,
407407
workspaceUrls: this.domainManagerService.getWorkspaceUrls(workspace),
408408
logo: workspace.logo,
409-
sso: workspace.workspaceSSOIdentityProviders.reduce(
410-
(acc, identityProvider) =>
411-
acc.concat(
412-
identityProvider.status === 'Inactive'
413-
? []
414-
: [
415-
{
416-
id: identityProvider.id,
417-
name: identityProvider.name,
418-
issuer: identityProvider.issuer,
419-
type: identityProvider.type,
420-
status: identityProvider.status,
421-
},
422-
],
423-
),
424-
[] as AvailableWorkspace['sso'],
425-
),
409+
sso:
410+
workspace.workspaceSSOIdentityProviders?.reduce(
411+
(acc, identityProvider) =>
412+
acc.concat(
413+
identityProvider.status === 'Inactive'
414+
? []
415+
: [
416+
{
417+
id: identityProvider.id,
418+
name: identityProvider.name,
419+
issuer: identityProvider.issuer,
420+
type: identityProvider.type,
421+
status: identityProvider.status,
422+
},
423+
],
424+
),
425+
[] as AvailableWorkspace['sso'],
426+
) ?? [],
426427
};
427428
}
428429

@@ -446,7 +447,12 @@ export class UserWorkspaceService extends TypeOrmQueryService<UserWorkspace> {
446447
({ workspace, appToken }) => {
447448
return {
448449
...this.castWorkspaceToAvailableWorkspace(workspace),
449-
...(appToken ? { personalInviteToken: appToken.value } : {}),
450+
...(appToken
451+
? {
452+
personalInviteToken: appToken.value,
453+
inviteHash: workspace.inviteHash,
454+
}
455+
: {}),
450456
};
451457
},
452458
),

0 commit comments

Comments
 (0)