TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/danielitoCode/AlejoTaller/llms.txt
Use this file to discover all available pages before exploring further.
shared-auth module is an Android library that centralizes all authentication logic for the AlejoTaller monorepo. Both the customer app (app) and the operator scanner app (alejotallerscan) depend on this module, ensuring that session management, user identity, and role enforcement are never duplicated across surfaces. All concrete infrastructure (Appwrite SDK calls, DataStore persistence) lives in shared-data; shared-auth exposes only pure domain contracts and use cases.
What It Exports
| Layer | Contents |
|---|---|
| Domain entities | User, UserProfile, OperatorAccess (role helpers) |
| Use cases | AuthUserCaseUse, AuthOperatorUserCaseUse, CloseSessionCaseUse, GetCurrentUserInfoCaseUse |
| Repository interfaces | AccountRepository, SessionManager |
| DI | SharedAuthFeatureModule (Koin object, wired by each app module) |
Domain Entities
User
The core identity entity. The init block enforces that the name is never blank at construction time.
UserProfile
Profile metadata fetched from Appwrite preferences. The role field drives access-control decisions across both apps.
OperatorAccess
Rather than a class, operator access is expressed as two top-level extension functions on String?. The allowed role set is kept private so callers cannot bypass it.
normalizeBusinessRole() trims and lowercases before comparison, making role checks case-insensitive and whitespace-safe.
Repository Interfaces
AccountRepository
Retrieves the currently authenticated user from the remote account backend.
SessionManager
Manages Appwrite email sessions. The port layer keeps the domain free of any Appwrite SDK types; concrete wiring lives in shared-data.
Both interfaces are implemented in
shared-data (AccountRepositoryImpl and AppwriteSessionManager). The domain module never imports the Appwrite SDK directly.Use Cases
All use cases follow the Kotlin operator-function convention — they are invoked ascaseUse(args) rather than caseUse.execute(args).
AuthUserCaseUse
Authenticates a user with an email/password pair via SessionManager. The email is trimmed before the call to strip accidental whitespace.
Result<String> containing the Appwrite userId on success.
AuthOperatorUserCaseUse
Operator-specific authentication that composes three other use cases. After a successful base login it fetches the current user and checks whether the role has operator access. If the role check fails, the session is immediately closed and an IllegalAccessException is thrown.
CloseSessionCaseUse
Terminates the current active session. Used both as a standalone logout action and internally by AuthOperatorUserCaseUse when a role check fails.
GetCurrentUserInfoCaseUse
Retrieves the full User object (including UserProfile) for the currently authenticated account.
Koin DI Module
SharedAuthFeatureModule is a Kotlin object that acts as a namespace marker for Koin bindings. Each consuming app module (:app, :alejotallerscan) wires the concrete implementations from shared-data and provides the use cases in its own Koin module, referencing SharedAuthFeatureModule as a logical grouping anchor.
Unit Tests
Tests use fake implementations (FakeSessionManager, FakeAccountRepository) so no Android runtime or Appwrite SDK is required.
AuthUserCaseUseTest
Verifies that the email is trimmed before it is forwarded to SessionManager.openEmailSession. Given an email with leading and trailing spaces (" USER@Alejo.dev "), the test asserts that sessionManager.openedEmail equals "USER@Alejo.dev" and the call succeeds.
AuthOperatorUserCaseUseTest
Covers three scenarios:
| Scenario | Role | Expected outcome |
|---|---|---|
| Operator role is allowed | "operator" | Result.success, closeCalls == 0 |
Admin role expressed as "administrator" | "administrator" | Result.success, closeCalls == 0 |
| Non-operator role is rejected | "viewer" | Result.failure<IllegalAccessException>, closeCalls == 1 |
Adding to a Gradle Module
shared-auth is an Android library. Add it as an implementation dependency in any Android module’s build.gradle.kts:
shared-auth itself depends on project(":shared-core") and the Appwrite Android SDK, so those transitive dependencies are pulled in automatically. The module requires minSdk = 26 and compiles against SDK 36.