Authentication
SalesArck uses Supabase for identity and SalesArck-owned data for authorization.
Current Flow
- The frontend signs in with Supabase OTP.
- The API verifies the access token server-side.
- The API resolves or creates the
usersrow. - The API loads tenant memberships from
tenant_users. - The API returns either a strict auth context or a looser profile response for
/auth/me.
Key Implementation Files
apps/api/src/middleware/auth.tsapps/api/src/middleware/auth-profile.tsapps/api/src/lib/resolve-user.tspackages/auth/src/supabase-server.ts
Role Derivation
The first authenticated request can derive a user role from Supabase metadata:
clientormerchantrequests map toclientwithpending_approvaladminrequests only stayadminwhen the email domain is approved- otherwise the user defaults to
consumer
Admin Email Domains
The current allowed admin domains are:
@salesarck.com@doshidhruv.com
Profile Response
GET /api/v1/auth/me returns the current session profile, including:
userIdroletenantIdsstatuscanUseAppneedsMerchantOnboardingemailphone- optional
codewhen app access is blocked
Important Invariants
- authentication is server-validated
- client payloads never decide tenant membership
- pending approval is a profile state, not a client-side guess
- admin email-domain checks cannot be bypassed by the UI
Written byDhruv Doshi