Skip to content

fix: disable SendGrid link tracking on magic-link emails - #55

Merged
mroderick merged 3 commits into
mainfrom
fix/magic-link-sendgrid-tracking
Aug 6, 2026
Merged

fix: disable SendGrid link tracking on magic-link emails#55
mroderick merged 3 commits into
mainfrom
fix/magic-link-sendgrid-tracking

Conversation

@mroderick

@mroderick mroderick commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

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 /LsClick tracking redirect, so recipients saw a long codebar.us tracking URL instead of the real sign-in link. This confused users during testing.

CleanShot 2026-07-28 at 14 43 04

Fix

Disable click and open tracking for this email only by passing tracking_settings in the mail/send request body. This overrides the account default per request, so other SendGrid emails keep tracking untouched. The request body is extracted into a pure buildMagicLinkPayload util (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.

tracking_settings: {
  click_tracking: { enable: false },
  open_tracking: { enable: false },
},

Tests

Added test/unit/magic-link-email.test.js asserting that click/open tracking are disabled and the real URL is embedded in the plain-text body.

Verification

Per-request tracking_settings is a documented field of the SendGrid v3 mail/send API (SendGrid docs: Mail Send) — the official example shows click_tracking.enable and open_tracking.enable toggled per message. This is scoped to one message, unlike the account-level PATCH /v3/tracking_settings/click endpoint (SendGrid docs: update click tracking settings).

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
mroderick force-pushed the fix/magic-link-sendgrid-tracking branch from fde6e6f to 469629b Compare August 6, 2026 08:44
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.
@mroderick

Copy link
Copy Markdown
Collaborator Author

Plain text version
image

HTML version
image

@mroderick

Copy link
Copy Markdown
Collaborator Author

I've verified this in production by deploying the branch and authenticating at https://codebar.io/auth/codebar 👍

@mroderick
mroderick marked this pull request as ready for review August 6, 2026 09:01
@mroderick
mroderick requested a review from till August 6, 2026 09:01
@mroderick

Copy link
Copy Markdown
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?

@till

till commented Aug 6, 2026

Copy link
Copy Markdown
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:

  • the email could use a from name
  • maybe better subject
  • friendlier text?
  • footer

You requested a link to log into your Codebar account:

If you didn't request this link, there's nothing for you to do.

Footer

@mroderick
mroderick merged commit 6fb4060 into main Aug 6, 2026
7 checks passed
@mroderick
mroderick deleted the fix/magic-link-sendgrid-tracking branch August 6, 2026 09:29
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