Username-First with UUID Fallback

Overview

The entire system now uses usernames as the primary identifier with UUID fallback for all user/creator lookups across routes and APIs.

This means:

  • Users visit /creators/john-doe (preferred) or /creators/<uuid> (also works)

  • Users visit /passport/alice-developer (preferred) or /passport/<uuid> (also works)

  • Users visit /ethos/artists/bob-musician (preferred) or /ethos/artists/<uuid> (also works)


Changes Made

1. Core Utility: Identifier Resolver (code/lib/identifier-resolver.ts)

New file that provides helper functions:

isUUID(str); // Check if string is UUID format
resolveIdentifierToCreator(id); // Resolve username/UUID → creator object
resolveIdentifierToUserId(id); // Resolve username/UUID → UUID
resolveIdentifierToUsername(id); // Resolve UUID → username

2. Creators API Endpoint (code/server/index.ts)

Updated GET /api/creators/:identifier to:

  • Accept username OR UUID in the :identifier parameter

  • Try username first (preferred)

  • Fall back to UUID lookup if username lookup fails

  • Return 404 if neither works

3. Creators Profile Component (code/client/pages/creators/CreatorProfile.tsx)

Updated to:

  • Import UUID/identifier resolver helpers

  • Accept both username and UUID as route parameters

  • Resolve UUID to username for canonical URL redirect (optional)

  • Maintain backwards compatibility with old UUID-based URLs

4. Ethos Artist Profile (code/client/pages/ethos/ArtistProfile.tsx)

Updated to:

  • Import identifier resolver helpers

  • Accept both username and userId as route parameters

  • Resolve username → userId before API call

  • Handle both patterns seamlessly

5. Passport Profile (code/client/pages/ProfilePassport.tsx)

Already supported username-first with UUID fallback:

  • Has built-in isUuid() function

  • Tries getProfileByUsername() first

  • Falls back to getProfileById() if username lookup fails

  • No changes needed - already implemented!

6. Creator Profile Validation (code/api/creators.ts)

Enforced usernames as required:

  • Username must be provided when creating creator profile

  • Username must be unique (409 Conflict if duplicate)

  • Username is normalized to lowercase

  • Validation on both client and server


Routes That Support Username-First with UUID Fallback

Route
Type
Status

/creators/:identifier

Frontend

✅ Updated

/passport/:identifier

Frontend

✅ Already working

/ethos/artists/:identifier

Frontend

✅ Updated

/api/creators/:identifier

Backend

✅ Updated


How It Works: Flow Example

Username Lookup (Preferred)

UUID Lookup (Fallback)

Username Resolution (For Ethos Artists)


Benefits

SEO-friendly URLs - Usernames are more human-readable than UUIDs ✅ Backwards compatible - Old UUID-based links still work ✅ Consistent behavior - All user profile routes work the same way ✅ User-friendly - Share /creators/john-doe instead of UUID ✅ Enforced usernames - Everyone has a username, eliminates UUID-only profiles


Implementation Details

UUID Detection

Lookup Priority

For any identifier:

  1. If it matches UUID pattern → Try UUID lookup directly

  2. If it doesn't match UUID pattern → Try username lookup first, then UUID fallback

  3. If both fail → Return 404 Not Found

Username Normalization

  • Usernames stored as lowercase

  • Lookups are case-insensitive

  • Users can visit /creators/John-Doe, /creators/JOHN-DOE, /creators/john-doe - all work

  • URLs always redirect to the canonical username (lowercase)


Client-Side API Functions

Using the Resolver Utilities


Database Consistency

Username Uniqueness

  • Usernames are unique in aethex_creators table

  • Enforced in API validation (returns 409 if duplicate)

  • Usernames are indexed for fast lookups

Required Field

  • username column is NOT NULL

  • All profiles created after enforcement have usernames

  • Migration: Existing profiles without usernames should be given auto-generated usernames


Future Improvements

  1. Profile slugs - Use human-friendly slugs instead of usernames (e.g., /profile/john-doe-developer)

  2. Username changes - Allow users to change usernames with proper redirects

  3. Vanity URLs - Custom profile URLs (e.g., /john)

  4. Social aliases - Link multiple usernames to one profile


Testing

Test Cases


Migration Checklist


Files Modified


Summary

Username-First with UUID Fallback is now implemented across the entire system.

All user-facing routes and APIs prefer usernames while maintaining backward compatibility with UUID-based URLs. Users must have a username to create a profile, ensuring consistent, SEO-friendly URLs throughout the AeThex ecosystem.

Last updated