Skip to content

Commit e3cb8f9

Browse files
Fix afterSignUpUrl base path in SignUpBox to include BASE_URL prefix
1 parent f572083 commit e3cb8f9

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

frontend/apps/gate/src/components/SignUp/SignUpBox.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ export default function SignUpBox(): JSX.Element {
3737
const {isDesignEnabled} = useDesign();
3838
const [flowError, setFlowError] = useState<string | null>(null);
3939

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

4247
const renderFlowContent = (
4348
components: EmbeddedFlowComponent[],
@@ -103,7 +108,7 @@ export default function SignUpBox(): JSX.Element {
103108
logoDisplay={!isDesignEnabled ? {xs: 'flex', md: 'none'} : {display: 'none'}}
104109
>
105110
<SignUp
106-
afterSignUpUrl={signInUrl}
111+
afterSignUpUrl={afterSignUpUrl}
107112
onFlowChange={(response: any) => {
108113
if (response?.failureReason) {
109114
setFlowError(response.failureReason as string);
@@ -151,7 +156,7 @@ export default function SignUpBox(): JSX.Element {
151156
<Button
152157
variant="text"
153158
onClick={() => {
154-
void navigate(signInUrl);
159+
void navigate(signInPath);
155160
}}
156161
sx={{
157162
p: 0,

frontend/apps/gate/src/components/SignUp/__tests__/SignUpBox.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ const createMockSignUpRenderProps = (overrides: Partial<MockSignUpRenderProps> =
9898

9999
let mockSignUpRenderProps: MockSignUpRenderProps = createMockSignUpRenderProps();
100100
let capturedOnFlowChange: ((response: unknown) => void) | undefined;
101+
let capturedAfterSignUpUrl: string | undefined;
101102

102103
vi.mock('@thunderid/react', async () => {
103104
const actual = await vi.importActual('@thunderid/react');
@@ -106,11 +107,14 @@ vi.mock('@thunderid/react', async () => {
106107
SignUp: ({
107108
children,
108109
onFlowChange = undefined,
110+
afterSignUpUrl = undefined,
109111
}: {
110112
children: (props: typeof mockSignUpRenderProps) => React.ReactNode;
111113
onFlowChange?: (response: unknown) => void;
114+
afterSignUpUrl?: string;
112115
}) => {
113116
capturedOnFlowChange = onFlowChange;
117+
capturedAfterSignUpUrl = afterSignUpUrl;
114118
return <div data-testid="thunderid-signup">{children(mockSignUpRenderProps)}</div>;
115119
},
116120
EmbeddedFlowComponentType: {
@@ -135,6 +139,7 @@ describe('SignUpBox', () => {
135139
});
136140
mockSignUpRenderProps = createMockSignUpRenderProps();
137141
capturedOnFlowChange = undefined;
142+
capturedAfterSignUpUrl = undefined;
138143
});
139144

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

553+
it('passes afterSignUpUrl as an absolute URL with origin and BASE_URL prefix to SignUp component', () => {
554+
render(<SignUpBox />);
555+
const expectedUrl = `${window.location.origin}${import.meta.env.BASE_URL.replace(/\/$/, '')}/signin`;
556+
expect(capturedAfterSignUpUrl).toBe(expectedUrl);
557+
});
558+
548559
it('navigates to sign in page when clicking sign in link', async () => {
549560
mockSignUpRenderProps = createMockSignUpRenderProps({
550561
components: [{id: 'block', type: 'BLOCK', components: []}],

0 commit comments

Comments
 (0)