Skip to content

Commit 90eecd1

Browse files
committed
chore(react): toggle BaseSignIn component based on platform version
1 parent fee4377 commit 90eecd1

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
import {
20+
EmbeddedSignInFlowInitiateResponse,
21+
EmbeddedSignInFlowHandleResponse,
22+
EmbeddedSignInFlowHandleRequestPayload,
23+
Platform,
24+
} from '@asgardeo/browser';
25+
import {FC, ReactElement} from 'react';
26+
import BaseSignInV1, {BaseSignInProps as BaseSignInV1Props} from './non-component-driven/BaseSignIn';
27+
import BaseSignInV2, {BaseSignInProps as BaseSignInV2Props} from './component-driven/BaseSignIn';
28+
import ComponentDrivenSignIn, {SignInRenderProps} from './component-driven/SignIn';
29+
import useAsgardeo from '../../../contexts/Asgardeo/useAsgardeo';
30+
31+
/**
32+
* Props for the BaseSignIn component.
33+
* Extends BaseSignInV1Props & BaseSignInV2Props for full compatibility with both React BaseSignIn components.
34+
*/
35+
export type BaseSignInProps = BaseSignInV1Props | BaseSignInV2Props;
36+
37+
const BaseSignIn: FC<BaseSignInProps> = (props: BaseSignInProps) => {
38+
const {platform} = useAsgardeo();
39+
40+
if (platform === Platform.AsgardeoV2) {
41+
return <BaseSignInV2 {...props as BaseSignInV2Props} />;
42+
}
43+
44+
return <BaseSignInV1 {...props as BaseSignInV1Props} />;
45+
};
46+
47+
export default BaseSignIn;

packages/react/src/components/presentation/SignIn/SignIn.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ import {
2323
Platform,
2424
} from '@asgardeo/browser';
2525
import {FC, ReactElement} from 'react';
26-
import BaseSignIn, {BaseSignInProps} from './non-component-driven/BaseSignIn';
27-
import ComponentDrivenSignIn, {SignInRenderProps} from './component-driven/SignIn';
26+
import BaseSignInV1, {BaseSignInProps as BaseSignInV1Props} from './non-component-driven/BaseSignIn';
27+
import SignInV2, {SignInRenderProps} from './component-driven/SignIn';
2828
import useAsgardeo from '../../../contexts/Asgardeo/useAsgardeo';
2929

3030
/**
3131
* Props for the SignIn component.
3232
* Extends BaseSignInProps for full compatibility with the React BaseSignIn component
3333
*/
34-
export type SignInProps = Pick<BaseSignInProps, 'className' | 'onSuccess' | 'onError' | 'variant' | 'size'> & {
34+
export type SignInProps = Pick<BaseSignInV1Props, 'className' | 'onSuccess' | 'onError' | 'variant' | 'size'> & {
3535
/**
3636
* Render function for custom UI (render props pattern).
3737
*/
@@ -102,20 +102,20 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', children, ...rest}
102102

103103
if (platform === Platform.AsgardeoV2) {
104104
return (
105-
<ComponentDrivenSignIn
105+
<SignInV2
106106
className={className}
107107
size={size}
108108
variant={rest.variant}
109109
onSuccess={rest.onSuccess}
110110
onError={rest.onError}
111111
>
112112
{children}
113-
</ComponentDrivenSignIn>
113+
</SignInV2>
114114
);
115115
}
116116

117117
return (
118-
<BaseSignIn
118+
<BaseSignInV1
119119
isLoading={isLoading || !isInitialized}
120120
afterSignInUrl={afterSignInUrl}
121121
onInitialize={handleInitialize}

packages/react/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ export * from './components/control/SignedOut';
118118
export {default as Loading} from './components/control/Loading';
119119
export * from './components/control/Loading';
120120

121-
export {default as BaseSignIn} from './components/presentation/SignIn/non-component-driven/BaseSignIn';
122-
export * from './components/presentation/SignIn/non-component-driven/BaseSignIn';
121+
export {default as BaseSignIn} from './components/presentation/SignIn/BaseSignIn';
122+
export * from './components/presentation/SignIn/BaseSignIn';
123123

124124
export {default as SignIn} from './components/presentation/SignIn/SignIn';
125125
export * from './components/presentation/SignIn/SignIn';

0 commit comments

Comments
 (0)