fix(auth): Invite with public url and social sso. (#10216)
Correct the URL parameter name from "inviteHash" to "workspaceInviteHash" and enhance domain URL handling for multi-workspace environments.
This commit is contained in:
@ -5,7 +5,6 @@ import { ReactNode, act } from 'react';
|
|||||||
import { MemoryRouter } from 'react-router-dom';
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
import { RecoilRoot, useRecoilValue } from 'recoil';
|
import { RecoilRoot, useRecoilValue } from 'recoil';
|
||||||
import { iconsState } from 'twenty-ui';
|
import { iconsState } from 'twenty-ui';
|
||||||
|
|
||||||
import { useAuth } from '@/auth/hooks/useAuth';
|
import { useAuth } from '@/auth/hooks/useAuth';
|
||||||
import { billingState } from '@/client-config/states/billingState';
|
import { billingState } from '@/client-config/states/billingState';
|
||||||
import { isDebugModeState } from '@/client-config/states/isDebugModeState';
|
import { isDebugModeState } from '@/client-config/states/isDebugModeState';
|
||||||
@ -17,6 +16,14 @@ import { isMultiWorkspaceEnabledState } from '@/client-config/states/isMultiWork
|
|||||||
import { renderHook } from '@testing-library/react';
|
import { renderHook } from '@testing-library/react';
|
||||||
import { email, mocks, password, results, token } from '../__mocks__/useAuth';
|
import { email, mocks, password, results, token } from '../__mocks__/useAuth';
|
||||||
|
|
||||||
|
const redirectSpy = jest.fn();
|
||||||
|
|
||||||
|
jest.mock('@/domain-manager/hooks/useRedirect', () => ({
|
||||||
|
useRedirect: jest.fn().mockImplementation(() => ({
|
||||||
|
redirect: redirectSpy,
|
||||||
|
})),
|
||||||
|
}));
|
||||||
|
|
||||||
const Wrapper = ({ children }: { children: ReactNode }) => (
|
const Wrapper = ({ children }: { children: ReactNode }) => (
|
||||||
<MockedProvider mocks={mocks} addTypename={false}>
|
<MockedProvider mocks={mocks} addTypename={false}>
|
||||||
<RecoilRoot>
|
<RecoilRoot>
|
||||||
@ -76,6 +83,22 @@ describe('useAuth', () => {
|
|||||||
expect(mocks[1].result).toHaveBeenCalled();
|
expect(mocks[1].result).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle google sign-in', async () => {
|
||||||
|
const { result } = renderHooks();
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
await result.current.signInWithGoogle({
|
||||||
|
workspaceInviteHash: 'workspaceInviteHash',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(redirectSpy).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining(
|
||||||
|
'/auth/google?workspaceInviteHash=workspaceInviteHash',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle sign-out', async () => {
|
it('should handle sign-out', async () => {
|
||||||
const { result } = renderHook(
|
const { result } = renderHook(
|
||||||
() => {
|
() => {
|
||||||
|
|||||||
@ -455,7 +455,7 @@ export const useAuth = () => {
|
|||||||
) => {
|
) => {
|
||||||
const url = new URL(`${REACT_APP_SERVER_BASE_URL}${path}`);
|
const url = new URL(`${REACT_APP_SERVER_BASE_URL}${path}`);
|
||||||
if (isDefined(params.workspaceInviteHash)) {
|
if (isDefined(params.workspaceInviteHash)) {
|
||||||
url.searchParams.set('inviteHash', params.workspaceInviteHash);
|
url.searchParams.set('workspaceInviteHash', params.workspaceInviteHash);
|
||||||
}
|
}
|
||||||
if (isDefined(params.workspacePersonalInviteToken)) {
|
if (isDefined(params.workspacePersonalInviteToken)) {
|
||||||
url.searchParams.set(
|
url.searchParams.set(
|
||||||
|
|||||||
@ -29,7 +29,7 @@ describe('DomainManagerService', () => {
|
|||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
customUrl: 'https://custom-host.com/',
|
customUrl: 'https://custom-host.com/',
|
||||||
subdomainUrl: 'https://subdomain.example.com/',
|
subdomainUrl: 'https://example.com/',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -39,6 +39,7 @@ describe('DomainManagerService', () => {
|
|||||||
.mockImplementation((key: string) => {
|
.mockImplementation((key: string) => {
|
||||||
const env = {
|
const env = {
|
||||||
FRONTEND_URL: 'https://example.com',
|
FRONTEND_URL: 'https://example.com',
|
||||||
|
IS_MULTIWORKSPACE_ENABLED: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
return env[key];
|
return env[key];
|
||||||
@ -104,7 +105,6 @@ describe('DomainManagerService', () => {
|
|||||||
.mockImplementation((key: string) => {
|
.mockImplementation((key: string) => {
|
||||||
const env = {
|
const env = {
|
||||||
FRONTEND_URL: 'https://example.com',
|
FRONTEND_URL: 'https://example.com',
|
||||||
|
|
||||||
IS_MULTIWORKSPACE_ENABLED: true,
|
IS_MULTIWORKSPACE_ENABLED: true,
|
||||||
DEFAULT_SUBDOMAIN: 'test',
|
DEFAULT_SUBDOMAIN: 'test',
|
||||||
};
|
};
|
||||||
@ -125,7 +125,6 @@ describe('DomainManagerService', () => {
|
|||||||
.mockImplementation((key: string) => {
|
.mockImplementation((key: string) => {
|
||||||
const env = {
|
const env = {
|
||||||
FRONTEND_URL: 'https://example.com',
|
FRONTEND_URL: 'https://example.com',
|
||||||
|
|
||||||
IS_MULTIWORKSPACE_ENABLED: true,
|
IS_MULTIWORKSPACE_ENABLED: true,
|
||||||
DEFAULT_SUBDOMAIN: 'default',
|
DEFAULT_SUBDOMAIN: 'default',
|
||||||
};
|
};
|
||||||
|
|||||||
@ -217,7 +217,9 @@ export class DomainManagerService {
|
|||||||
private getTwentyWorkspaceUrl(subdomain: string) {
|
private getTwentyWorkspaceUrl(subdomain: string) {
|
||||||
const url = this.getFrontUrl();
|
const url = this.getFrontUrl();
|
||||||
|
|
||||||
url.hostname = `${subdomain}.${url.hostname}`;
|
url.hostname = this.environmentService.get('IS_MULTIWORKSPACE_ENABLED')
|
||||||
|
? `${subdomain}.${url.hostname}`
|
||||||
|
: url.hostname;
|
||||||
|
|
||||||
return url.toString();
|
return url.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user