fix: disable SendGrid link tracking on magic-link emails - #55
Merged
Conversation
Move the SendGrid mail/send request body into a pure buildMagicLinkPayload util so it can be unit-tested without a SendGrid call or the auth instance's DB pool.
Pass per-request tracking_settings in the mail/send body so the magic-link URL reads as the real codebar.io link instead of a long /LsClick redirect.
mroderick
force-pushed
the
fix/magic-link-sendgrid-tracking
branch
from
August 6, 2026 08:44
fde6e6f to
469629b
Compare
Render the sign-in link as a button in an HTML part alongside the existing plain-text part. HTML-escape the href so the token/query string survives attribute embedding.
Collaborator
Author
Collaborator
Author
|
I've verified this in production by deploying the branch and authenticating at https://codebar.io/auth/codebar 👍 |
mroderick
marked this pull request as ready for review
August 6, 2026 09:01
Collaborator
Author
|
@till do you think we should use the HTML version, which arguably is slightly more difficult for people to recognise as genuinely coming from codebar? |
Collaborator
|
@mroderick Good question, maybe it's better to show the link in HTML and text versions of the email? Maybe a different ticket, but:
|
till
approved these changes
Aug 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Problem
Magic-link emails were sent as plain text with the sign-in URL embedded directly in the body. SendGrid's click tracking rewrote that link into a long
/LsClicktracking redirect, so recipients saw a longcodebar.ustracking URL instead of the real sign-in link. This confused users during testing.Fix
Disable click and open tracking for this email only by passing
tracking_settingsin themail/sendrequest body. This overrides the account default per request, so other SendGrid emails keep tracking untouched. The request body is extracted into a purebuildMagicLinkPayloadutil (src/app/utils/magic-link-email.js) so the shape is unit-testable without a SendGrid call or the auth instance's DB pool.The magic-link URL now reads as the actual codebar.io destination — which is also more phishing-resistant, since recipients can verify the domain before clicking.
Tests
Added
test/unit/magic-link-email.test.jsasserting that click/open tracking are disabled and the real URL is embedded in the plain-text body.Verification
Per-request
tracking_settingsis a documented field of the SendGrid v3mail/sendAPI (SendGrid docs: Mail Send) — the official example showsclick_tracking.enableandopen_tracking.enabletoggled per message. This is scoped to one message, unlike the account-levelPATCH /v3/tracking_settings/clickendpoint (SendGrid docs: update click tracking settings).