Skip to content

Commit 494e681

Browse files
committed
feat(react): update signUp method to use navigate utility and change button variant to solid
1 parent 763994f commit 494e681

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

packages/react/src/AsgardeoReactClient.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ import {
4242
HttpRequestConfig,
4343
HttpResponse,
4444
Storage,
45+
navigate,
46+
getRedirectBasedSignUpUrl,
47+
Config,
4548
TokenExchangeRequestConfig,
4649
} from '@asgardeo/browser';
4750
import AuthAPI from './__temp__/api';
@@ -333,32 +336,19 @@ class AsgardeoReactClient<T extends AsgardeoReactConfig = AsgardeoReactConfig> e
333336
override async signUp(options?: SignUpOptions): Promise<void>;
334337
override async signUp(payload: EmbeddedFlowExecuteRequestPayload): Promise<EmbeddedFlowExecuteResponse>;
335338
override async signUp(...args: any[]): Promise<void | EmbeddedFlowExecuteResponse> {
336-
if (args.length === 0) {
337-
throw new AsgardeoRuntimeError(
338-
'No arguments provided for signUp method.',
339-
'react-AsgardeoReactClient-ValidationError-001',
340-
'react',
341-
'The signUp method requires at least one argument, either a SignUpOptions object or an EmbeddedFlowExecuteRequestPayload.',
342-
);
343-
}
344-
339+
const configData = await this.asgardeo.getConfigData();
345340
const firstArg = args[0];
346341

347342
if (typeof firstArg === 'object' && 'flowType' in firstArg) {
348-
const configData = await this.asgardeo.getConfigData();
349343
const baseUrl: string = configData?.baseUrl;
350344

351345
return executeEmbeddedSignUpFlow({
352346
baseUrl,
353347
payload: firstArg as EmbeddedFlowExecuteRequestPayload,
354348
});
355349
}
356-
throw new AsgardeoRuntimeError(
357-
'Not implemented',
358-
'react-AsgardeoReactClient-ValidationError-002',
359-
'react',
360-
'The signUp method with SignUpOptions is not implemented in the React client.',
361-
);
350+
351+
navigate(getRedirectBasedSignUpUrl(configData as Config));
362352
}
363353

364354
async request(requestConfig?: HttpRequestConfig): Promise<HttpResponse<any>> {

packages/react/src/components/actions/SignUpButton/BaseSignUpButton.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ const BaseSignUpButton: ForwardRefExoticComponent<BaseSignUpButtonProps & RefAtt
9898
disabled={isLoading}
9999
loading={isLoading}
100100
type="button"
101+
color="primary"
102+
variant="solid"
101103
{...rest}
102104
>
103105
{children}

packages/react/src/components/actions/SignUpButton/SignUpButton.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
import {AsgardeoRuntimeError} from '@asgardeo/browser';
20+
import {navigate} from '@asgardeo/browser';
2021
import {forwardRef, ForwardRefExoticComponent, MouseEvent, ReactElement, Ref, RefAttributes, useState} from 'react';
2122
import BaseSignUpButton, {BaseSignUpButtonProps} from './BaseSignUpButton';
2223
import useAsgardeo from '../../../contexts/Asgardeo/useAsgardeo';
@@ -83,9 +84,7 @@ const SignUpButton: ForwardRefExoticComponent<SignUpButtonProps & RefAttributes<
8384

8485
// If a custom `signUpUrl` is provided, use it for navigation.
8586
if (signUpUrl) {
86-
window.history.pushState(null, '', signUpUrl);
87-
88-
window.dispatchEvent(new PopStateEvent('popstate', {state: null}));
87+
navigate(signUpUrl);
8988
} else {
9089
await signUp();
9190
}

0 commit comments

Comments
 (0)