Skip to content

fix: require login actions for magic links#1329

Open
memleakd wants to merge 3 commits into
codeigniter4:developfrom
memleakd:fix/magic-link-login-actions
Open

fix: require login actions for magic links#1329
memleakd wants to merge 3 commits into
codeigniter4:developfrom
memleakd:fix/magic-link-login-actions

Conversation

@memleakd
Copy link
Copy Markdown
Contributor

Description

This fixes a gap in the magic-link login flow.

Password login already respects configured login auth actions, such as Email-based 2FA. Magic-link login, however, could finish immediately after the token was verified. So an app could have 2FA enabled for normal login, but magic-link login would not go through that same action flow.

With this PR, magic-link login now starts the configured login action when one applies to the user. If an action is required, the user is sent to the normal auth-action screen first, and the magic-link login is only treated as complete after that action passes.

The existing magicLogin session value and magicLogin event still work. They are just delayed until the login action is completed, so they continue to mean "the user has finished logging in with a magic link".

I also added a short note to the docs, plus tests for normal and conditional login actions.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

michalsn
michalsn previously approved these changes May 31, 2026
Copy link
Copy Markdown
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix makes sense. I only wonder... if we add another passwordless login method later, it may need the same handling. A generic pending login-method marker would keep this reusable... but maybe we should keep things simple and refactor it later if it will be needed.

@michalsn michalsn requested a review from datamweb May 31, 2026 09:03
@michalsn michalsn dismissed their stale review May 31, 2026 09:06

I thought only PHPStan is failing, but PHPUnit fails too.

@michalsn
Copy link
Copy Markdown
Member

@memleakd Please rebase and fix PHPUnit issues.

memleakd added 2 commits May 31, 2026 12:30
- Start configured login actions during magic-link verification
- Preserve magicLogin notification until pending actions complete
- Cover normal and conditional login-action magic-link flows
- Document that magic-link login finishes after required login actions

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
@memleakd memleakd force-pushed the fix/magic-link-login-actions branch from 9263659 to 5d0b89d Compare May 31, 2026 10:41
@memleakd
Copy link
Copy Markdown
Contributor Author

@memleakd Please rebase and fix PHPUnit issues.

Done

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
@memleakd
Copy link
Copy Markdown
Contributor Author

I only wonder... if we add another passwordless login method later, it may need the same handling. A generic pending login-method marker would keep this reusable...

Good point, thanks for calling that out. I refactored it to use a generic marker instead of magic-link-specific.

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.

2 participants