Skip to content

fix(magiclink): store the link in the user's environment - #177

Merged
juicycleff merged 4 commits into
mainfrom
fix/magiclink-env-id
Nov 14, 2026
Merged

juicycleff merged 4 commits into
mainfrom
fix/magiclink-env-id

Conversation

@juicycleff

@juicycleff juicycleff commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

POST /v1/magic-link/send returns a 500 for every address that has an account. It builds the token with account.NewVerification, which leaves EnvID empty. In the Postgres store, authsome_verifications.env_id has a foreign key to authsome_environments, so the insert fails:

insert or update on table "authsome_verifications" violates foreign key constraint "fk_authsome_verifications_env"
DETAIL: Key (env_id)=() is not present in table "authsome_environments".

middleware.InternalError hides the cause, so clients only see internal error. Unknown addresses still get a 200, because they return before any token is made, and that hid the bug. The handler is the same in v1.10.0.

Fix

The token now takes the user's environment (v.EnvID = u.EnvID), the way email verification in service.go already does.

Tests

  • TestMagicLink_Send_StoresUserEnvironment checks the stored token's EnvID. The memory store doesn't enforce the foreign key, so the test checks the field directly. It fails without the fix and passes with it.
  • go test ./plugins/magiclink/ passes.
  • I ran it against wakflo's dev stack with this branch swapped in: the send returns 200, the email goes out, and the link signs in.

Also

The Format check failed on main: two mfa tests from 2255356 had imports out of goimports -local github.com/xraph/authsome order. A separate commit regroups them, with imports only.

Lint failed on main for the same reason: eight golangci-lint findings in the mfa and organization changes (errcheck, gocritic, govet shadow, ineffassign, unparam). A third commit clears them without changing behaviour. golangci-lint run on the whole repo reports 0 issues.

🤖 Generated with Claude Code

juicycleff and others added 3 commits November 13, 2026 17:25
/send built its token with account.NewVerification, which leaves the
environment empty. The SQL stores hold env_id to a foreign key, so the
insert failed and every send for a real account returned a 500. Unknown
addresses still got a 200, which hid it. The memory store doesn't enforce
the key, so the tests never saw it.

The token now takes the user's environment, the way email verification
already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2255356 left two mfa tests with imports out of goimports order, so the
Format check fails on main and on every PR. Imports only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The mfa and organization changes left eight findings that fail Lint on
main and every PR. None changes behaviour:

- organization: check the notification plugin's type assertion, and name
  authorizeInvitationChange's results.
- mfa: stop the SMS override's errors shadowing the handler's err.
- mfa tests: drop the dead first sid, and the parameters that only ever
  got one value (the rate limit, the enrolled phone), which become
  constants.
- organization tests: the invite helper's result was never used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Both sides cleared the same golangci-lint findings in plugins/mfa; keep
main's versions, which landed with #176.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juicycleff
juicycleff merged commit 83ec6be into main Nov 14, 2026
17 checks passed
@juicycleff
juicycleff deleted the fix/magiclink-env-id branch November 14, 2026 00:41
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.

1 participant