Skip to content

Commit 1b71f92

Browse files
committed
feat(react): add signInUrl and signUpUrl to BaseConfig and update SignInButton behavior
1 parent 488b225 commit 1b71f92

File tree

6 files changed

+33
-35
lines changed

6 files changed

+33
-35
lines changed

packages/javascript/src/models/config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ export interface BaseConfig<T = unknown> extends WithPreferences {
7676
* scopes: ["openid", "profile", "email"]
7777
*/
7878
scopes?: string | string[] | undefined;
79+
80+
/**
81+
* Optional URL to redirect the user to sign-in.
82+
* By default, this will be the sign-in page of Asgardeo.
83+
* If you want to use a custom sign-in page, you can provide the URL here and use the `SignIn` component to render it.
84+
*/
85+
signInUrl?: string | undefined;
86+
87+
/**
88+
* Optional URL to redirect the user to sign-up.
89+
* By default, this will be the sign-up page of Asgardeo.
90+
* If you want to use a custom sign-up page, you can provide the URL here
91+
* and use the `SignUp` component to render it.
92+
*/
93+
signUpUrl?: string | undefined;
7994
}
8095

8196
export interface WithPreferences {

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const SignInButton: ForwardRefExoticComponent<SignInButtonProps & RefAttributes<
7171
HTMLButtonElement,
7272
SignInButtonProps
7373
>(({children, onClick, preferences, ...rest}: SignInButtonProps, ref: Ref<HTMLButtonElement>): ReactElement => {
74-
const {signIn} = useAsgardeo();
74+
const {signIn, signInUrl} = useAsgardeo();
7575
const {t} = useTranslation(preferences?.i18n);
7676

7777
const [isLoading, setIsLoading] = useState(false);
@@ -80,7 +80,14 @@ const SignInButton: ForwardRefExoticComponent<SignInButtonProps & RefAttributes<
8080
try {
8181
setIsLoading(true);
8282

83-
await signIn();
83+
// If a custom `signInUrl` is provided, use it for navigation.
84+
if (signInUrl) {
85+
window.history.pushState(null, '', signInUrl);
86+
87+
window.dispatchEvent(new PopStateEvent('popstate', {state: null}));
88+
} else {
89+
await signIn();
90+
}
8491

8592
if (onClick) {
8693
onClick(e);

packages/react/src/contexts/Asgardeo/AsgardeoContext.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {Context, createContext} from 'react';
2222
* Props interface of {@link AsgardeoContext}
2323
*/
2424
export type AsgardeoContextProps = {
25+
signInUrl: string;
2526
afterSignInUrl: string;
2627
baseUrl: string;
2728
isInitialized: boolean;
@@ -58,8 +59,9 @@ export type AsgardeoContextProps = {
5859
* Context object for managing the Authentication flow builder core context.
5960
*/
6061
const AsgardeoContext: Context<AsgardeoContextProps | null> = createContext<null | AsgardeoContextProps>({
61-
afterSignInUrl: '',
62-
baseUrl: '',
62+
signInUrl: undefined,
63+
afterSignInUrl: undefined,
64+
baseUrl: undefined,
6365
isInitialized: false,
6466
isLoading: true,
6567
isSignedIn: false,

packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
5050
children,
5151
scopes,
5252
preferences,
53+
signInUrl,
5354
...rest
5455
}: PropsWithChildren<AsgardeoProviderProps>): ReactElement => {
5556
const reRenderCheckRef: RefObject<boolean> = useRef(false);
@@ -230,6 +231,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
230231
return (
231232
<AsgardeoContext.Provider
232233
value={{
234+
signInUrl,
233235
afterSignInUrl,
234236
baseUrl,
235237
isInitialized: isInitializedSync,

samples/teamspace-react/src/components/Header/PublicActions.tsx

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,7 @@ export default function PublicActions({className = '', showMobileActions = false
1616
// Mobile menu actions
1717
return (
1818
<div className="pt-4 border-t border-gray-200 space-y-2">
19-
<SignInButton>
20-
{({isLoading}) => (
21-
<Button
22-
onClick={() => {
23-
navigate('/signin');
24-
}}
25-
disabled={isLoading}
26-
size="lg"
27-
color="primary"
28-
variant="secondary"
29-
>
30-
{isLoading ? 'Signing in...' : 'Sign In'}
31-
</Button>
32-
)}
33-
</SignInButton>
19+
<SignInButton />
3420
</div>
3521
);
3622
}
@@ -39,22 +25,7 @@ export default function PublicActions({className = '', showMobileActions = false
3925
<div className={`flex items-center space-x-4 ${className}`}>
4026
{/* Desktop CTA */}
4127
<div className="hidden md:flex items-center space-x-4">
42-
<SignInButton>Sign In with Redirect</SignInButton>
43-
<SignInButton>
44-
{({isLoading}) => (
45-
<Button
46-
onClick={() => {
47-
navigate('/signin');
48-
}}
49-
disabled={isLoading}
50-
size="lg"
51-
color="primary"
52-
variant="secondary"
53-
>
54-
{isLoading ? 'Signing in...' : 'Sign In'}
55-
</Button>
56-
)}
57-
</SignInButton>
28+
<SignInButton />
5829
<SignUpButton>
5930
{({isLoading}) => (
6031
<Button

samples/teamspace-react/src/main.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ createRoot(document.getElementById('root')!).render(
1111
afterSignInUrl={import.meta.env.VITE_ASGARDEO_AFTER_SIGN_IN_URL}
1212
afterSignOutUrl={import.meta.env.VITE_ASGARDEO_AFTER_SIGN_OUT_URL}
1313
clientId={import.meta.env.VITE_ASGARDEO_CLIENT_ID}
14+
signInUrl={import.meta.env.VITE_ASGARDEO_SIGN_IN_URL}
1415
scopes={[
1516
'openid',
1617
'address',

0 commit comments

Comments
 (0)