Skip to content

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

VariableTypeDefaultDescription
appNamestringMyAppThe name of your application
prefixstringAppPrefix for generated classes (e.g. App, My)
uiKitPackageNamestringapp_ui_kitName of the UI kit package
isForMonorepobooleantrueWhether this will be part of a monorepo structure
stateManagementenumcubitState management solution: bloc, cubit, riverpod, provider
authBackendenumrest_apiAuth 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 via signInWithPassword, registration via signUp.
  • Firebase — uses firebase_auth. Token refresh is explicit via getIdToken(true). Sign-in via signInWithEmailAndPassword, registration via createUserWithEmailAndPassword.
  • REST API — uses dio + flutter_secure_storage. Calls POST /auth/login, POST /auth/register, and POST /auth/refresh. Access and refresh tokens are stored securely in the device keychain/keystore.

Usage

Interactive

bash
archipelago generate auth_sdk

Non-interactive (CI)

bash
archipelago generate auth_sdk --config my_config.json

Generated 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.yaml

Per-Feature Translations

Auth has its own slang configuration with feature-scoped translations:

yaml
# slang.yaml
translate_var: authL10n       # Access via context.authL10n
enum_name: AuthLocale
class_name: AuthTranslations

Translation strings cover login, register, and validation messages in English and Indonesian.

Key Features

  • Event-driven authAuthSDK emits 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 AppLocaleAuthLocale for 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 when stateManagement == bloc
  • isCubit — true when stateManagement == cubit
  • usesBloc — true when isBloc || isCubit (both use flutter_bloc)
  • isRiverpod — true when stateManagement == riverpod
  • isProvider — true when stateManagement == 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.

dart
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):

VariableTypeDefaultDescription
includeAnonymousAuthbooleanfalseGenerate anonymous sign-in support with AuthStatus.anonymous
dart
await getIt<AuthSDK>().signInAnonymously();
// AuthSDK.status == AuthStatus.anonymous

Anonymous users can later be promoted to a full account via linkWithCredential().

Phone OTP Flow

Enable phone OTP with the includePhoneOtp variable (default: false):

VariableTypeDefaultDescription
includePhoneOtpbooleanfalseGenerate requestPhoneOtp + verifyPhoneOtp methods
dart
// 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-exports
  • slang + slang_flutter — Per-feature translations
  • slang_build_runner (dev) — Code generation

Built by Banua Coder