Summary
Fixes DASH-430 — "Email Id in settings is wrong (some random id gets appended)".
In resolveUser(), the user's email was sourced directly from Better Auth's getSession() response (data.user.email), which may include an appended identifier. This email propagates to settings pages (debug info @org_member_email), the sidebar menu, analytics, and isComposioUser checks.
The fix adds a Prisma lookup against the Users table to retrieve the canonical email, falling back to the Better Auth email if the DB lookup fails. This aligns with the frontend repo, which uses org_member.email from the /api/v3/auth/session/info API rather than Better Auth's email.
Review & Testing Checklist for Human
Notes
- Local lint (
oxlint) and typecheck (tsgo) were unavailable in the dev environment so the change has not been validated locally — CI results should be checked.
- The
user.email from resolveUser is used broadly (settings, isComposioUser checks, analytics, Intercom, DataDog), so if the DB email is correct this fix has wide positive impact.
Link to Devin session: https://app.devin.ai/sessions/f71ebaa6bb904d8d91a7490538d5a6f1
Requested by: @palash-c