@@ -50,6 +50,7 @@ import {SignIn as UISignIn} from '../../oxygen-ui-react-auth-components';
5050import generateThemeSignIn from '../../theme/generate-theme-sign-in' ;
5151import SPACryptoUtils from '../../utils/crypto-utils' ;
5252import './sign-in.scss' ;
53+ import IdentifierFirst from './fragments/IdentifierFirst' ;
5354
5455/**
5556 * This component provides the sign-in functionality.
@@ -63,7 +64,6 @@ import './sign-in.scss';
6364const SignIn : FC < SignInProps > = ( props : SignInProps ) : ReactElement => {
6465 const { brandingProps, showFooter = true , showLogo = true , showSignUp} = props ;
6566
66- const [ authResponse , setAuthResponse ] = useState < AuthApiResponse > ( ) ;
6767 const [ isComponentLoading , setIsComponentLoading ] = useState < boolean > ( true ) ;
6868 const [ alert , setAlert ] = useState < AlertType > ( ) ;
6969 const [ showSelfSignUp , setShowSelfSignUp ] = useState < boolean > ( showSignUp ) ;
@@ -93,7 +93,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
9393 */
9494 authorize ( )
9595 . then ( ( response : AuthApiResponse ) => {
96- setAuthResponse ( response ) ;
96+ authContext ?. setAuthResponse ( response ) ;
9797 setIsComponentLoading ( false ) ;
9898 } )
9999 . catch ( ( error : Error ) => {
@@ -111,14 +111,14 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
111111 const handleAuthenticate = async ( authenticatorId : string , authParams ?: { [ key : string ] : string } ) : Promise < void > => {
112112 setAlert ( undefined ) ;
113113
114- if ( authResponse === undefined ) {
114+ if ( authContext ?. authResponse === undefined ) {
115115 throw new AsgardeoUIException ( 'REACT_UI-SIGN_IN-HA-IV02' , 'Auth response is undefined.' ) ;
116116 }
117117
118118 authContext . setIsAuthLoading ( true ) ;
119119
120120 const resp : AuthApiResponse = await authenticate ( {
121- flowId : authResponse . flowId ,
121+ flowId : authContext ?. authResponse . flowId ,
122122 selectedAuthenticator : {
123123 authenticatorId,
124124 params : authParams ,
@@ -162,13 +162,13 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
162162 window . removeEventListener ( 'message' , messageEventHandler ) ;
163163 } ) ;
164164 } else if ( metaData . promptType === PromptType . UserPrompt ) {
165- setAuthResponse ( resp ) ;
165+ authContext ?. setAuthResponse ( resp ) ;
166166 }
167167 } else if ( resp . flowStatus === FlowStatus . SuccessCompleted && resp . authData ) {
168168 /**
169169 * when the authentication is successful, generate the token
170170 */
171- setAuthResponse ( resp ) ;
171+ authContext ?. setAuthResponse ( resp ) ;
172172
173173 const authInstance : UIAuthClient = AuthClient . getInstance ( ) ;
174174 const state : string = ( await authInstance . getDataLayer ( ) . getTemporaryDataParameter ( 'state' ) ) . toString ( ) ;
@@ -177,14 +177,14 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
177177
178178 authContext . setAuthentication ( ) ;
179179 } else if ( resp . flowStatus === FlowStatus . FailIncomplete ) {
180- setAuthResponse ( {
180+ authContext ?. setAuthResponse ( {
181181 ...resp ,
182- nextStep : authResponse . nextStep ,
182+ nextStep : authContext ?. authResponse . nextStep ,
183183 } ) ;
184184
185185 setAlert ( { alertType : { error : true } , key : keys . common . error } ) ;
186186 } else {
187- setAuthResponse ( resp ) ;
187+ authContext ?. setAuthResponse ( resp ) ;
188188 setShowSelfSignUp ( false ) ;
189189 }
190190
@@ -211,7 +211,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
211211 } ;
212212
213213 const renderSignIn = ( ) : ReactElement => {
214- const authenticators : Authenticator [ ] = authResponse ?. nextStep ?. authenticators ;
214+ const authenticators : Authenticator [ ] = authContext ?. authResponse ?. nextStep ?. authenticators ;
215215
216216 if ( authenticators ) {
217217 const usernamePasswordAuthenticator : Authenticator = authenticators . find (
@@ -235,6 +235,27 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
235235 ) ;
236236 }
237237
238+ const identifierFirstAuthenticator : Authenticator = authenticators . find (
239+ ( authenticator : Authenticator ) => authenticator . authenticator === 'Identifier First' ,
240+ ) ;
241+
242+ if ( identifierFirstAuthenticator ) {
243+ return (
244+ < IdentifierFirst
245+ brandingProps = { brandingProps }
246+ authenticator = { identifierFirstAuthenticator }
247+ handleAuthenticate = { handleAuthenticate }
248+ showSelfSignUp = { showSelfSignUp }
249+ alert = { alert }
250+ renderLoginOptions = { renderLoginOptions (
251+ authenticators . filter (
252+ ( auth : Authenticator ) => auth . authenticatorId !== identifierFirstAuthenticator . authenticatorId ,
253+ ) ,
254+ ) }
255+ />
256+ ) ;
257+ }
258+
238259 if ( authenticators . length === 1 ) {
239260 if ( authenticators [ 0 ] . authenticator === 'TOTP' ) {
240261 return (
@@ -249,7 +270,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
249270 if (
250271 // TODO: change after api based auth gets fixed
251272 new SPACryptoUtils ( )
252- . base64URLDecode ( authResponse . nextStep . authenticators [ 0 ] . authenticatorId )
273+ . base64URLDecode ( authContext ?. authResponse . nextStep . authenticators [ 0 ] . authenticatorId )
253274 . split ( ':' ) [ 0 ] === 'email-otp-authenticator'
254275 ) {
255276 return (
@@ -265,7 +286,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
265286 if (
266287 // TODO: change after api based auth gets fixed
267288 new SPACryptoUtils ( )
268- . base64URLDecode ( authResponse . nextStep . authenticators [ 0 ] . authenticatorId )
289+ . base64URLDecode ( authContext ?. authResponse . nextStep . authenticators [ 0 ] . authenticatorId )
269290 . split ( ':' ) [ 0 ] === 'sms-otp-authenticator'
270291 ) {
271292 return (
@@ -326,7 +347,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
326347 { showLogo && ! ( isLoading || isComponentLoading ) && (
327348 < UISignIn . Image className = "asgardeo-sign-in-logo" src = { imgUrl } />
328349 ) }
329- { authResponse ?. flowStatus !== FlowStatus . SuccessCompleted && ! isAuthenticated && (
350+ { authContext ?. authResponse ?. flowStatus !== FlowStatus . SuccessCompleted && ! isAuthenticated && (
330351 < >
331352 { renderSignIn ( ) }
332353
@@ -355,7 +376,7 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
355376 ) }
356377 </ >
357378 ) }
358- { ( authResponse ?. flowStatus === FlowStatus . SuccessCompleted || isAuthenticated ) && (
379+ { ( authContext ?. authResponse ?. flowStatus === FlowStatus . SuccessCompleted || isAuthenticated ) && (
359380 < div style = { { backgroundColor : 'white' , padding : '1rem' } } > Successfully Authenticated</ div >
360381 ) }
361382 </ UISignIn >
0 commit comments