Skip to content

feat: run PreAuthentication at managed login - #1177

Merged
hughgrigg merged 1 commit into
mainfrom
feat/hg/managed-login-pre-authentication
Aug 30, 2026
Merged

feat: run PreAuthentication at managed login#1177
hughgrigg merged 1 commit into
mainfrom
feat/hg/managed-login-pre-authentication

Conversation

@hughgrigg

@hughgrigg hughgrigg commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

A local user signing in at the hosted domain ran no authentication trigger, where the same user signing in through InitiateAuth ran both, so a handler that logs or blocks a sign-in passed its API tests and waved every managed login sign-in through. PreAuthentication now runs there under the PreAuthentication_Authentication source real Cognito reports from /login, for a password and for a passkey alike. It runs once the user is known and before the password is checked, which is where the API sign-ins run it, so a sign-in the pool is about to refuse reaches the handler too. A passkey runs it on the request that asks for the credential rather than on the one presenting it, matching the USER_AUTH sign-in, and only an asked request holds a session to present against, so it runs once either way. A browser coming back on the managed login session it already holds runs nothing, which is what the trigger's own docs say of a renewed session. A handler that throws is drawn on the sign-in form the way a wrong password is. PostAuthentication stays unfired and the docs say why.

One thing worth knowing about the test fixture. simCognitoWithHostedPasskey sets the pool's SignInPolicy with UpdateUserPool, and an update replaces a pool's settings whole, so the request was taking the pool's LambdaConfig back off it. That is real Cognito behaviour rather than a simulator bug, and the fixture now carries the triggers through the update with a comment saying why.

Resolves #1173

Summary by CodeRabbit

  • New Features
    • Hosted password and passkey sign-ins now invoke the configured PreAuthentication trigger during initial sign-in.
    • Trigger responses and errors are surfaced while preserving relevant form data.
    • Trigger context includes the sign-in source and username.
  • Bug Fixes
    • Session renewals no longer re-run PreAuthentication triggers.
    • Documented managed-login behavior, including cases where sign-in triggers do not run.

A local user signing in at the hosted domain ran no authentication trigger, where the same user
signing in through `InitiateAuth` ran both, so a handler that logs or blocks a sign-in passed its API
tests and waved every managed login sign-in through. `PreAuthentication` now runs there under the
`PreAuthentication_Authentication` source real Cognito reports from `/login`, for a password and for
a passkey alike. It runs once the user is known and before the password is checked, which is where
the API sign-ins run it, so a sign-in the pool is about to refuse reaches the handler too. A passkey
runs it on the request that asks for the credential rather than on the one presenting it, matching
the `USER_AUTH` sign-in, and only an asked request holds a session to present against, so it runs
once either way. A browser coming back on the managed login session it already holds runs nothing,
which is what the trigger's own docs say of a renewed session. A handler that throws is drawn on the
sign-in form the way a wrong password is. `PostAuthentication` stays unfired and the docs say why.

Resolves #1173
@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 78d317d0-2866-4b6c-82c1-bcc48ea49eea

📥 Commits

Reviewing files that changed from the base of the PR and between 197c468 and d9cd915.

📒 Files selected for processing (7)
  • docs/services/cognito/README.md
  • src/service/cognito/command/hosted/sim-cognito-hosted-commands.ts
  • src/service/cognito/command/hosted/sim-cognito-hosted-passkey-sign-in.ts
  • src/service/cognito/command/hosted/sim-cognito-hosted-password-sign-in.ts
  • src/service/cognito/command/hosted/sim-cognito-hosted-sign-in.ts
  • src/service/cognito/command/hosted/sim-cognito-managed-login-triggers.iso.test.ts
  • test/cognito/hosted-passkey-fixture.ts

Included review availability: 0 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.


📝 Walkthrough

Walkthrough

Hosted managed-login password and passkey sign-ins now run PreAuthentication. Trigger failures return to the sign-in form. Reused managed-login sessions run no sign-in trigger. Tests and Cognito documentation cover these behaviors.

Changes

Managed-login authentication triggers

Layer / File(s) Summary
Trigger wiring and password flow
src/service/cognito/command/hosted/sim-cognito-hosted-commands.ts, src/service/cognito/command/hosted/sim-cognito-hosted-sign-in.ts, src/service/cognito/command/hosted/sim-cognito-hosted-password-sign-in.ts
Hosted sign-in components receive user-pool triggers. Password sign-in invokes PreAuthentication before existing credential and status checks.
Passkey trigger flow and test fixture
src/service/cognito/command/hosted/sim-cognito-hosted-passkey-sign-in.ts, test/cognito/hosted-passkey-fixture.ts
Passkey sign-in invokes PreAuthentication before readiness validation and challenge issuance. The fixture accepts Lambda trigger configuration and preserves it during pool updates.
Behavior validation and documentation
src/service/cognito/command/hosted/sim-cognito-managed-login-triggers.iso.test.ts, docs/services/cognito/README.md
Tests cover successful and rejected password and passkey sign-ins, handler refusals, trigger data, and session reuse. Documentation describes supported behavior and limitations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to d9cd9

This change runs the pre-authentication handler for managed password and passkey sign-ins while preserving existing session behavior; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: running PreAuthentication during managed login.
Description check ✅ Passed The description explains the behavior, trigger source, password and passkey flows, renewal behavior, handler errors, documentation, fixture change, and linked issue. It does not include the template c…
Linked Issues check ✅ Passed The changes satisfy issue #1173. They add PreAuthentication for password and passkey managed-login sign-ins, use the required source, handle rejected sign-ins, avoid retriggering on session renewal, p…
Out of Scope Changes check ✅ Passed The code, tests, fixture update, and documentation changes directly support issue #1173 and its acceptance criteria. No unrelated code changes are identified.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 6 files. (1 skipped: 1 …
Full details: Description check

Explanation

The description explains the behavior, trigger source, password and passkey flows, renewal behavior, handler errors, documentation, fixture change, and linked issue. It does not include the template checkboxes, but the substantive description is complete.

Full details: Linked Issues check

Explanation

The changes satisfy issue #1173. They add PreAuthentication for password and passkey managed-login sign-ins, use the required source, handle rejected sign-ins, avoid retriggering on session renewal, preserve Lambda configuration in the fixture, and document the behavior.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 6 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/hg/managed-login-pre-authentication

Comment @coderabbitai help to get the list of available commands.

@hughgrigg

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@hughgrigg
hughgrigg merged commit 5c28b0d into main Aug 30, 2026
7 checks passed
@hughgrigg
hughgrigg deleted the feat/hg/managed-login-pre-authentication branch August 30, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Run PreAuthentication when a local user signs in at managed login

1 participant