Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions frontend/apps/gate/src/components/SignUp/SignUpBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ export default function SignUpBox(): JSX.Element {
const {isDesignEnabled} = useDesign();
const [flowError, setFlowError] = useState<string | null>(null);

const signInUrl = ROUTES.AUTH.SIGN_IN;
// For React Router navigate() — basename is handled by the router.
const signInPath = ROUTES.AUTH.SIGN_IN;
// For window.location.href and new URL() (via afterSignUpUrl) — React Router basename is
// bypassed, so an absolute URL with origin + base path must be constructed explicitly.
// Vite appends a trailing slash to BASE_URL.
const afterSignUpUrl = `${window.location.origin}${import.meta.env.BASE_URL.replace(/\/$/, '')}${signInPath}`;

const renderFlowContent = (
components: EmbeddedFlowComponent[],
Expand Down Expand Up @@ -103,7 +108,7 @@ export default function SignUpBox(): JSX.Element {
logoDisplay={!isDesignEnabled ? {xs: 'flex', md: 'none'} : {display: 'none'}}
>
<SignUp
afterSignUpUrl={signInUrl}
afterSignUpUrl={afterSignUpUrl}
onFlowChange={(response: any) => {
if (response?.failureReason) {
setFlowError(response.failureReason as string);
Expand Down Expand Up @@ -151,7 +156,7 @@ export default function SignUpBox(): JSX.Element {
<Button
variant="text"
onClick={() => {
void navigate(signInUrl);
void navigate(signInPath);
}}
sx={{
p: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const createMockSignUpRenderProps = (overrides: Partial<MockSignUpRenderProps> =

let mockSignUpRenderProps: MockSignUpRenderProps = createMockSignUpRenderProps();
let capturedOnFlowChange: ((response: unknown) => void) | undefined;
let capturedAfterSignUpUrl: string | undefined;

vi.mock('@thunderid/react', async () => {
const actual = await vi.importActual('@thunderid/react');
Expand All @@ -106,11 +107,14 @@ vi.mock('@thunderid/react', async () => {
SignUp: ({
children,
onFlowChange = undefined,
afterSignUpUrl = undefined,
}: {
children: (props: typeof mockSignUpRenderProps) => React.ReactNode;
onFlowChange?: (response: unknown) => void;
afterSignUpUrl?: string;
}) => {
capturedOnFlowChange = onFlowChange;
capturedAfterSignUpUrl = afterSignUpUrl;
return <div data-testid="thunderid-signup">{children(mockSignUpRenderProps)}</div>;
},
EmbeddedFlowComponentType: {
Expand All @@ -135,6 +139,7 @@ describe('SignUpBox', () => {
});
mockSignUpRenderProps = createMockSignUpRenderProps();
capturedOnFlowChange = undefined;
capturedAfterSignUpUrl = undefined;
});

it('renders without crashing', () => {
Expand Down Expand Up @@ -545,6 +550,12 @@ describe('SignUpBox', () => {
expect(screen.getByText('Sign in')).toBeInTheDocument();
});

it('passes afterSignUpUrl as an absolute URL with origin and BASE_URL prefix to SignUp component', () => {
render(<SignUpBox />);
const expectedUrl = `${window.location.origin}${import.meta.env.BASE_URL.replace(/\/$/, '')}/signin`;
expect(capturedAfterSignUpUrl).toBe(expectedUrl);
});

it('navigates to sign in page when clicking sign in link', async () => {
mockSignUpRenderProps = createMockSignUpRenderProps({
components: [{id: 'block', type: 'BLOCK', components: []}],
Expand Down
Loading