Send magic links through SMTP email #198

Merged
erik merged 2 commits from feat/task-bf36a41f-smtp-magic-links into main 2026-06-23 23:53:39 -05:00
Owner

Summary

Add SMTP-backed magic-link email delivery for production sites while preserving dev-mode log output.

Task

Task: #task-bf36a41f

Changes

  • Added SMTP magic-link delivery via nodemailer.
  • Added environment-based SMTP config parsing for host, port, secure mode, username/password, sender email, and sender name.
  • Preserved AUTH_DEV_MODE=true log-output behavior with no SMTP requirement.
  • Kept missing/invalid production SMTP config on the existing delivery-not-configured path so no magic link is created silently.
  • Added delivery and magic-link tests for SMTP success, dev-mode behavior, and missing/invalid config.
  • Documented SMTP variables in .env.example and template setup docs.

Testing

  • Unit tests added/updated
  • Manual testing performed

Verification:

  • npm exec --workspace @slugkit/template-site -- vitest run --config ../../vitest.config.ts src/auth/__tests__/delivery.test.ts src/auth/__tests__/magic-links.test.ts src/routes/__tests__/auth.test.ts
  • ./scripts/pre-pr.sh
  • npm run build && npm run lint && npm test

Checklist

  • ./scripts/pre-pr.sh passes
  • Documentation updated
  • No unrelated changes included
## Summary Add SMTP-backed magic-link email delivery for production sites while preserving dev-mode log output. ## Task Task: #task-bf36a41f ## Changes - Added SMTP magic-link delivery via `nodemailer`. - Added environment-based SMTP config parsing for host, port, secure mode, username/password, sender email, and sender name. - Preserved `AUTH_DEV_MODE=true` log-output behavior with no SMTP requirement. - Kept missing/invalid production SMTP config on the existing `delivery-not-configured` path so no magic link is created silently. - Added delivery and magic-link tests for SMTP success, dev-mode behavior, and missing/invalid config. - Documented SMTP variables in `.env.example` and template setup docs. ## Testing - [x] Unit tests added/updated - [x] Manual testing performed Verification: - `npm exec --workspace @slugkit/template-site -- vitest run --config ../../vitest.config.ts src/auth/__tests__/delivery.test.ts src/auth/__tests__/magic-links.test.ts src/routes/__tests__/auth.test.ts` - `./scripts/pre-pr.sh` - `npm run build && npm run lint && npm test` ## Checklist - [x] `./scripts/pre-pr.sh` passes - [x] Documentation updated - [x] No unrelated changes included
feat: send magic links through smtp
All checks were successful
CI / build-lint-test (pull_request) Successful in 49s
a322fd6685
Task: #task-bf36a41f
Author
Owner

PR Review: Approved

Summary: SMTP-backed magic-link delivery is implemented in scope. The changes add environment-based SMTP configuration, preserve dev-mode log delivery, fail clearly before creating a magic-link row when required SMTP config is absent/invalid, and update docs/tests.

Acceptance criteria:

  • Production-style configuration can send a magic-link email via SMTP — createMagicLinkDelivery builds a Nodemailer transport from SMTP env config and sends text/html magic-link mail.
  • AUTH_DEV_MODE=true still logs the magic link and does not require SMTP — dev-mode branch returns the existing log delivery path and is covered by tests.
  • Missing SMTP configuration with dev mode disabled returns a clear error and does not silently drop the login link — config errors use MagicLinkDeliveryNotConfiguredError, createMagicLink returns delivery-not-configured, and tests assert no DB row is created.
  • SMTP host, port, authentication, TLS/secure mode, sender address, and sender name are configurable — SMTP_HOST, SMTP_PORT, SMTP_USERNAME, SMTP_PASSWORD, SMTP_SECURE, SMTP_FROM_EMAIL, and SMTP_FROM_NAME are parsed and documented.
  • Template .env.example and setup documentation explain SMTP configuration and magic-link delivery — updated in template/site/.env.example and template/site/README.md.
  • Tests cover SMTP delivery success, dev-mode behavior, and configuration failure cases — new/updated Vitest coverage includes SMTP success, dev logging, and config failure paths.

Verification reviewed:

  • Local targeted tests passed: npm exec --workspace @slugkit/template-site -- vitest run --config ../../vitest.config.ts src/auth/__tests__/delivery.test.ts src/auth/__tests__/magic-links.test.ts src/routes/__tests__/auth.test.ts (3 files, 23 tests).
  • Local full pre-PR gate passed: ./scripts/pre-pr.sh (format, lint, typecheck, all workspace tests: 49 files, 369 tests).
  • Forgejo Actions run #275 is successful for commit a322fd6685 (build-lint-test, pull_request).

Blocking issues: none.

Warnings: none.

Final verdict: approved. Do not merge until explicit human merge approval.

## PR Review: Approved Summary: SMTP-backed magic-link delivery is implemented in scope. The changes add environment-based SMTP configuration, preserve dev-mode log delivery, fail clearly before creating a magic-link row when required SMTP config is absent/invalid, and update docs/tests. Acceptance criteria: - [x] Production-style configuration can send a magic-link email via SMTP — `createMagicLinkDelivery` builds a Nodemailer transport from SMTP env config and sends text/html magic-link mail. - [x] `AUTH_DEV_MODE=true` still logs the magic link and does not require SMTP — dev-mode branch returns the existing log delivery path and is covered by tests. - [x] Missing SMTP configuration with dev mode disabled returns a clear error and does not silently drop the login link — config errors use `MagicLinkDeliveryNotConfiguredError`, `createMagicLink` returns `delivery-not-configured`, and tests assert no DB row is created. - [x] SMTP host, port, authentication, TLS/secure mode, sender address, and sender name are configurable — `SMTP_HOST`, `SMTP_PORT`, `SMTP_USERNAME`, `SMTP_PASSWORD`, `SMTP_SECURE`, `SMTP_FROM_EMAIL`, and `SMTP_FROM_NAME` are parsed and documented. - [x] Template `.env.example` and setup documentation explain SMTP configuration and magic-link delivery — updated in `template/site/.env.example` and `template/site/README.md`. - [x] Tests cover SMTP delivery success, dev-mode behavior, and configuration failure cases — new/updated Vitest coverage includes SMTP success, dev logging, and config failure paths. Verification reviewed: - Local targeted tests passed: `npm exec --workspace @slugkit/template-site -- vitest run --config ../../vitest.config.ts src/auth/__tests__/delivery.test.ts src/auth/__tests__/magic-links.test.ts src/routes/__tests__/auth.test.ts` (3 files, 23 tests). - Local full pre-PR gate passed: `./scripts/pre-pr.sh` (format, lint, typecheck, all workspace tests: 49 files, 369 tests). - Forgejo Actions run #275 is successful for commit `a322fd6685` (`build-lint-test`, pull_request). Blocking issues: none. Warnings: none. Final verdict: approved. Do not merge until explicit human merge approval.
Respect explicit auth dev mode
All checks were successful
CI / build-lint-test (pull_request) Successful in 44s
9f2d44db88
Author
Owner

PR review completed for task task-bf36a41f after update 9f2d44d.

Result: approved

Acceptance criteria: 6/6 met, 0 missing.

Verification:

  • Reviewed updated PR diff and commit 9f2d44d.
  • Confirmed AUTH_DEV_MODE=false now forces SMTP delivery even when NODE_ENV is non-production.
  • Confirmed test coverage was updated for explicit dev-mode disabling under NODE_ENV=development.
  • Local targeted tests passed: npm exec --workspace @slugkit/template-site -- vitest run --config ../../vitest.config.ts src/auth/__tests__/delivery.test.ts src/auth/__tests__/magic-links.test.ts src/routes/__tests__/auth.test.ts (3 files, 23 tests).
  • Local full gate passed: ./scripts/pre-pr.sh (format, lint, typecheck, all workspace tests: 49 files, 369 tests).
  • Forgejo Actions #276 succeeded for commit 9f2d44d (build-lint-test, pull_request).
  • Manual SMTP validation: after updating the local Migadu password and restarting dev, the app is configured to use SMTP rather than logging links.

Blocking issues: none.
Warnings: none.

Merge gate: waiting for explicit human merge approval.

PR Review Worker Result

  • pr: open
  • review: approved
  • pr_comment: posted
  • task_comment: posted
  • blocking_issues: 0
  • warnings: 0
  • criteria_total: 6
  • criteria_met: 6
  • criteria_missing: 0
PR review completed for task `task-bf36a41f` after update `9f2d44d`. Result: approved Acceptance criteria: 6/6 met, 0 missing. Verification: - Reviewed updated PR diff and commit `9f2d44d`. - Confirmed `AUTH_DEV_MODE=false` now forces SMTP delivery even when `NODE_ENV` is non-production. - Confirmed test coverage was updated for explicit dev-mode disabling under `NODE_ENV=development`. - Local targeted tests passed: `npm exec --workspace @slugkit/template-site -- vitest run --config ../../vitest.config.ts src/auth/__tests__/delivery.test.ts src/auth/__tests__/magic-links.test.ts src/routes/__tests__/auth.test.ts` (3 files, 23 tests). - Local full gate passed: `./scripts/pre-pr.sh` (format, lint, typecheck, all workspace tests: 49 files, 369 tests). - Forgejo Actions #276 succeeded for commit `9f2d44d` (`build-lint-test`, pull_request). - Manual SMTP validation: after updating the local Migadu password and restarting dev, the app is configured to use SMTP rather than logging links. Blocking issues: none. Warnings: none. Merge gate: waiting for explicit human merge approval. PR Review Worker Result - pr: open - review: approved - pr_comment: posted - task_comment: posted - blocking_issues: 0 - warnings: 0 - criteria_total: 6 - criteria_met: 6 - criteria_missing: 0
erik merged commit dba0286d02 into main 2026-06-23 23:53:39 -05:00
erik deleted branch feat/task-bf36a41f-smtp-magic-links 2026-06-23 23:53:39 -05:00
Sign in to join this conversation.
No description provided.