Service Layer medium complexity Shared Component mobile
2
Dependencies
1
Dependents
3
Entities
1
Integrations

Description

Application-layer service orchestrating authentication flows against the Supabase Auth backend. Abstracts Supabase SDK calls, maps errors to domain-level exceptions, and returns typed session results to callers.

Feature: Email and Password Login

auth-service

Summaries

The Authentication Service is the central gateway controlling who can access the application and its data. It protects the business from unauthorized access, ensures compliance with security best practices by delegating credential storage to Supabase's managed authentication infrastructure, and reduces the cost and risk of building custom identity management. As a shared component used across all features requiring authentication, it delivers consistent security behavior throughout the product, reducing the risk of fragmented or inconsistent access control that could expose user data or violate privacy regulations.

The Authentication Service is a medium-complexity shared component with two external dependencies: the Supabase Auth client SDK and the Auth Repository. Its shared nature means any delays or breaking changes will affect all features that require authenticated sessions. Teams building downstream features should treat this service as a critical path dependency and plan integration testing accordingly. Deployment requires Supabase project configuration, API key management, and environment-specific secrets handling.

Testing should cover success flows, error mapping for all known Supabase error codes, session refresh edge cases, and auth state stream behavior under network interruption scenarios.

Authentication Service acts as an anti-corruption layer between the Supabase Auth SDK and the application domain. It wraps Supabase SDK calls (signInWithEmailPassword, signOut, getSession, refreshSession) and maps Supabase-specific error codes into typed domain exceptions, preventing Supabase implementation details from leaking into the BLoC or UI layers. The onAuthStateChanged stream should be forwarded from Supabase's own auth state stream, allowing the app to reactively respond to session expiry or external sign-out events. The service returns typed AuthResult and Session?

objects. As a shared component, changes to its interface must be coordinated across all consumers. Consider caching getCurrentSession() to avoid redundant SDK calls in hot paths.

Responsibilities

  • Execute email/password sign-in against Supabase Auth
  • Map Supabase error codes to typed domain exceptions
  • Return session and user profile on successful authentication
  • Expose sign-out and session refresh operations

Interfaces

signInWithEmailPassword(String email, String password) Future<AuthResult>
signOut() Future<void>
refreshSession() Future<AuthResult>
getCurrentSession() Session?
onAuthStateChanged Stream<AuthState>

Relationships

Dependencies (2)

Components this component depends on

Dependents (1)

Components that depend on this component

Related Data Entities (3)

Data entities managed by this component

Used Integrations (1)

External integrations and APIs this component relies on

API Contract

View full contract →
REST /api/v1/auth 5 endpoints
GET /api/v1/auth
GET /api/v1/auth/:id
POST /api/v1/auth
PUT /api/v1/auth/:id
DELETE /api/v1/auth/:id