Skip to content

feat: add email-based account setup for new users#143

Closed
jakebromberg wants to merge 3 commits intomainfrom
feature/email-account-setup
Closed

feat: add email-based account setup for new users#143
jakebromberg wants to merge 3 commits intomainfrom
feature/email-account-setup

Conversation

@jakebromberg
Copy link
Member

Summary

Implements email-based account setup flow for new users created by admins.

Changes

  1. Unified Email System (shared/authentication/src/email.ts)

    • Refactored to discriminated union pattern with WXYCEmail type
    • New sendEmail() function handles all transactional emails
    • Added accountSetup email type: "Welcome! Set up your password"
  2. New User Detection (shared/authentication/src/auth.definition.ts)

    • sendResetPassword callback detects new users (empty realName)
    • New users receive welcome/setup email instead of password reset
  3. Admin Role (shared/authentication/src/auth.roles.ts)

    • Added admin role with full roster permissions

How It Works

  1. Admin creates user → random UUID password (never shared)
  2. Backend detects new user (no realName) → sends "Welcome" email
  3. User clicks link → sets their own password
  4. User logs in → onboarding to fill in profile

Related PRs

Test Plan

  • Unit tests pass: npm run test:unit
  • Build succeeds: npm run build
  • Integration test with frontend PR

Jake Bromberg added 2 commits February 1, 2026 22:56
Add roster resource to access control statements. Add roster write
permission to stationManager role. Add new admin role with full
permissions including roster management.
Refactor email system to use discriminated union pattern with unified
sendEmail() function. Add accountSetup email type that sends a "Welcome!
Set up your password" message to new users created by admin.

The sendResetPassword callback now detects new users (empty realName)
and sends accountSetup email instead of passwordReset email.

- Add WXYCEmail discriminated union type
- Add sendEmail() function with getEmailContent() factory
- Add accountSetup email type with welcome messaging
- Update sendResetPassword to detect new vs existing users
- Add comprehensive unit tests for all email types
- Add capabilities text[] column to auth_user table
- Include capabilities in JWT payload via definePayload
- Register capabilities as Better Auth additionalField
- Add unit tests for capability storage and JWT structure
@jakebromberg
Copy link
Member Author

Cross-repo coordination

This PR is part of a coordinated change to add cross-cutting capabilities (editor, webmaster) to the auth system:

Repo Change Status
wxyc-shared Phase 1: Capabilities module with types and helpers ✅ Merged to main
Backend-Service Phase 2: Database column, schema, JWT payload 👈 This PR
dj-site Phase 3: Capability management UI in roster WXYC/dj-site#117

These should be merged in order: shared → backend → dj-site

bin: ["read", "write"],
catalog: ["read", "write"],
flowsheet: ["read", "write"],
roster: ["read", "write"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is there a roster?

@jakebromberg
Copy link
Member Author

Closing in favor of #148, which extracts the capabilities work (the still-needed part of this PR). The email account-setup changes here have been superseded by #145 and #147 on main.

@jakebromberg jakebromberg deleted the feature/email-account-setup branch February 12, 2026 22:39
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