Skip to content

Commit

Permalink
fix: set active username after auth attempt to maintain consistent us…
Browse files Browse the repository at this point in the history
…er context
  • Loading branch information
yuhengshs committed Nov 22, 2024
1 parent b66249d commit 8b5320d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/auth/src/client/flows/userAuth/handleUserAuthFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { getAuthUserAgentValue } from '../../../utils';
import { handlePasswordSRP } from '../shared/handlePasswordSRP';
import { assertValidationError } from '../../../errors/utils/assertValidationError';
import { AuthValidationErrorCode } from '../../../errors/types/validation';
import { setActiveSignInUsername } from '../../../providers/cognito/utils/signInHelpers';

export interface HandleUserAuthFlowInput {
username: string;
Expand Down Expand Up @@ -107,11 +108,18 @@ export async function handleUserAuthFlow({
}),
});

return initiateAuth(
const response = await initiateAuth(
{
region: getRegionFromUserPoolId(userPoolId),
userAgentValue: getAuthUserAgentValue(AuthAction.SignIn),
},
jsonReq,
);

// Set the active username immediately after successful authentication attempt
// If a user starts a new sign-in while another sign-in is incomplete,
// this ensures we're tracking the correct user for subsequent auth challenges.
setActiveSignInUsername(username);

return response;
}

0 comments on commit 8b5320d

Please sign in to comment.