Email Linking System
Overview
The email linking system allows users to authenticate with multiple email addresses that all resolve to the same account. This is particularly useful for developers with both work (@aethex.dev) and personal email addresses.
Architecture
Database Tables
user_email_links
user_email_linksLinks multiple email addresses to a single user account.
- id: UUID (primary key)
- user_id: UUID (FK to user_profiles.user_id)
- email: TEXT (unique)
- is_primary: BOOLEAN (marks the main email)
- verified_at: TIMESTAMP
- linked_at: TIMESTAMP
- created_at: TIMESTAMP
- updated_at: TIMESTAMPuser_profiles (additions)
user_profiles (additions)User Flows
Flow 1: Login with Linked Email
Flow 2: Link Additional Email (Settings)
API Endpoints
POST /api/user/resolve-linked-email
/api/user/resolve-linked-emailResolve a linked email to its primary email address.
Request:
Response (linked email):
Response (non-linked email):
POST /api/user/link-email
/api/user/link-emailLink two existing user accounts by merging one into the other.
Request:
Response:
POST /api/user/link-mrpiglr-accounts (Admin Only)
/api/user/link-mrpiglr-accounts (Admin Only)Special endpoint to link the mrpiglr accounts.
Request:
Response:
Implementation Details
Authentication Resolution
When a user tries to sign in with a linked email:
First attempt: Try with provided email (normal auth flow)
If it fails with "invalid credentials":
Check
/api/user/resolve-linked-emailIf email is linked, get primary email
Retry with primary email
If successful, user is logged in
This is transparent to the user - they can log in with any linked email.
Data Transfer on Merge
When two accounts are merged:
Achievements: Transferred to primary account
Creator Profile: Transferred or preserved if not duplicate
Applications: Transferred to primary account
Discord Links: Transferred (avoiding duplicates)
Web3 Wallets: Transferred (avoiding duplicates)
Email Links: Both emails added to user_email_links table
Profile: Source profile marked as
merged_to_user_id
For Developers (Dev Accounts)
Developer accounts with @aethex.dev email:
is_dev_account = trueprimary_email = "@aethex.dev email"Public profile shows work email
Can link personal email for authentication convenience
Usage Examples
Link mrpiglr Accounts
Link Any Two Accounts
Check Email Resolution
Database Migration
Applied via: code/supabase/migrations/20250206_add_email_linking.sql
Includes:
user_email_linkstable with RLS policiesget_primary_user_by_email()functionColumns on
user_profilesfor dev accounts and primary emailProper indexes for performance
Future Enhancements
Email Verification: Add verification flow before linking new emails
Settings UI: Add "Linked Emails" section in user settings
Email Change Request: Allow users to change primary email
Admin Dashboard: View all linked emails for a user
Notification: Email both addresses when a new email is linked
Last updated
