@@ -165,7 +165,7 @@ export type SignInProps = {
165165 * ```
166166 */
167167const SignIn : FC < SignInProps > = ( { className, size = 'medium' , onSuccess, onError, variant, children} ) => {
168- const { applicationId, afterSignInUrl, signIn, isInitialized, isLoading, baseUrl } = useAsgardeo ( ) ;
168+ const { applicationId, afterSignInUrl, signIn, isInitialized, isLoading} = useAsgardeo ( ) ;
169169 const { t} = useTranslation ( ) ;
170170
171171 // State management for the flow
@@ -186,13 +186,20 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
186186
187187 /**
188188 * Initialize the authentication flow.
189+ * Priority: flowId > applicationId (from context) > applicationId (from URL)
189190 */
190191 const initializeFlow = async ( ) : Promise < void > => {
191- const applicationIdFromUrl : string = new URL ( window . location . href ) . searchParams . get ( 'applicationId' ) ;
192+ const urlParams = new URL ( window . location . href ) . searchParams ;
193+ const flowIdFromUrl : string = urlParams . get ( 'flowId' ) ;
194+ const applicationIdFromUrl : string = urlParams . get ( 'applicationId' ) ;
192195
193- if ( ! applicationIdFromUrl && ! applicationId ) {
196+ // Priority order: flowId from URL > applicationId from context > applicationId from URL
197+ const effectiveApplicationId = applicationId || applicationIdFromUrl ;
198+
199+ // Validate that we have either flowId or applicationId
200+ if ( ! flowIdFromUrl && ! effectiveApplicationId ) {
194201 const error = new AsgardeoRuntimeError (
195- `Application ID is required for authentication` ,
202+ 'Either flowId or applicationId is required for authentication' ,
196203 'SignIn-initializeFlow-RuntimeError-001' ,
197204 'react' ,
198205 'Something went wrong while trying to sign in. Please try again later.' ,
@@ -203,10 +210,20 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
203210
204211 try {
205212 setFlowError ( null ) ;
206- const response : EmbeddedSignInFlowResponseV2 = await signIn ( {
207- applicationId : applicationId || applicationIdFromUrl ,
208- flowType : EmbeddedFlowType . Authentication ,
209- } ) as EmbeddedSignInFlowResponseV2 ;
213+
214+ let response : EmbeddedSignInFlowResponseV2 ;
215+
216+ // Use flowId if available (priority), otherwise use applicationId
217+ if ( flowIdFromUrl ) {
218+ response = await signIn ( {
219+ flowId : flowIdFromUrl ,
220+ } ) as EmbeddedSignInFlowResponseV2 ;
221+ } else {
222+ response = await signIn ( {
223+ applicationId : effectiveApplicationId ,
224+ flowType : EmbeddedFlowType . Authentication ,
225+ } ) as EmbeddedSignInFlowResponseV2 ;
226+ }
210227
211228 const { flowId, components} = normalizeFlowResponse ( response , t ) ;
212229
0 commit comments