auth_sdk Free
Authentication feature SDK with login/register pages, event-driven listener pattern, scoped DI, and per-feature slang translations.
Version: 1.1.0
Variables
| Variable | Type | Default | Description |
|---|---|---|---|
| appName | string | MyApp | The name of your application |
| prefix | string | App | Prefix for generated classes (e.g. App, My) |
| uiKitPackageName | string | app_ui_kit | Name of the UI kit package |
| isForMonorepo | boolean | true | Whether this will be part of a monorepo structure |
| stateManagement | enum | cubit | State management solution: bloc, cubit, riverpod, provider |
| authBackend | enum | rest_api | Auth backend provider: supabase, firebase, rest_api |
Backend Support
The authBackend variable controls which authentication provider the generated datasource and repository use.
- Supabase — uses
supabase_flutter. Token refresh is handled automatically by the Supabase client. Sign-in viasignInWithPassword, registration viasignUp. - Firebase — uses
firebase_auth. Token refresh is explicit viagetIdToken(true). Sign-in viasignInWithEmailAndPassword, registration viacreateUserWithEmailAndPassword. - REST API — uses
dio+flutter_secure_storage. CallsPOST /auth/login,POST /auth/register, andPOST /auth/refresh. Access and refresh tokens are stored securely in the device keychain/keystore.
Usage
Interactive
archipelago generate auth_sdkNon-interactive (CI)
archipelago generate auth_sdk --config my_config.jsonGenerated Structure
features/
└── auth/
├── auth_api/
│ ├── lib/
│ │ ├── auth_api.dart
│ │ └── src/
│ │ ├── auth_event.dart
│ │ ├── auth_sdk.dart # Auth FeatureSDK contract
│ │ ├── auth_status.dart
│ │ ├── enums/
│ │ │ └── logout_reason.dart
│ │ └── typedefs.dart
│ └── pubspec.yaml
└── auth_impl/
├── l10n/ # Per-feature translations
│ ├── auth_en.i18n.json
│ └── auth_id.i18n.json
├── lib/
│ ├── auth_impl.dart
│ └── src/
│ ├── auth_sdk_impl.dart
│ ├── data/
│ │ ├── datasources/
│ │ ├── models/
│ │ └── repositories/
│ ├── di/
│ │ ├── auth_global_module.dart
│ │ ├── auth_local_module.dart
│ │ └── injector.dart
│ ├── domain/usecases/
│ ├── l10n/
│ │ └── auth_translations.g.dart # Generated by slang
│ ├── presentation/
│ │ ├── auth_shell_page.dart # Locale sync + DI scope
│ │ ├── login/login_page.dart # Uses context.authL10n
│ │ └── register/register_page.dart # Uses context.authL10n
│ └── router/
├── slang.yaml # Auth-specific slang config
├── build.yaml # Includes slang_build_runner
└── pubspec.yamlPer-Feature Translations
Auth has its own slang configuration with feature-scoped translations:
# slang.yaml
translate_var: authL10n # Access via context.authL10n
enum_name: AuthLocale
class_name: AuthTranslationsTranslation strings cover login, register, and validation messages in English and Indonesian.
Key Features
- Event-driven auth —
AuthSDKemits events (login success, logout) that the app listens to reactively - Dual-GetIt DI — Global (AuthSDK) + local (repos, usecases) scoped to shell page lifecycle
- Locale sync — Shell page maps global
AppLocale→AuthLocalefor feature-scoped translations - Localized validation — Form validation messages use
context.authL10n.validation.*
State Management
The brick generates state management files based on the stateManagement variable passed from the parent flutter_modular_monorepo brick. Supported values: bloc, cubit, riverpod, provider.
Derived boolean variables computed in pre_gen.dart:
isBloc— true whenstateManagement == blocisCubit— true whenstateManagement == cubitusesBloc— true whenisBloc || isCubit(both useflutter_bloc)isRiverpod— true whenstateManagement == riverpodisProvider— true whenstateManagement == provider
Pages use typed design system extensions (context.colors, context.typography, etc.) instead of Theme.of(context).
Auth Completeness Add-ons (since 1.1.0)
Three additional capabilities were added in PR #276 and are now part of the auth_sdk contract.
Delete Account
deleteAccount() is a mandatory addition — no brick variable gates it. Apple App Store and Google Play now require apps offering account creation to also offer account deletion.
await getIt<AuthSDK>().deleteAccount();The implementation revokes tokens, clears stored credentials, and emits an AuthEvent.accountDeleted event.
Anonymous Sessions
Enable guest sessions with the includeAnonymousAuth variable (default: false):
| Variable | Type | Default | Description |
|---|---|---|---|
| includeAnonymousAuth | boolean | false | Generate anonymous sign-in support with AuthStatus.anonymous |
await getIt<AuthSDK>().signInAnonymously();
// AuthSDK.status == AuthStatus.anonymousAnonymous users can later be promoted to a full account via linkWithCredential().
Phone OTP Flow
Enable phone OTP with the includePhoneOtp variable (default: false):
| Variable | Type | Default | Description |
|---|---|---|---|
| includePhoneOtp | boolean | false | Generate requestPhoneOtp + verifyPhoneOtp methods |
// Step 1 — request OTP
final handle = await getIt<AuthSDK>().requestPhoneOtp('+6281234567890');
// Step 2 — verify OTP code entered by user
await getIt<AuthSDK>().verifyPhoneOtp(
verificationHandle: handle,
code: userEnteredCode,
);The verificationHandle is an opaque token returned by requestPhoneOtp. Its format depends on the authBackend — for Firebase it is the verificationId; for REST API it is an opaque server-issued handle stored in FlutterSecureStorage.
Dependencies
locale_core— Global locale state and slang re-exportsslang+slang_flutter— Per-feature translationsslang_build_runner(dev) — Code generation