corbado_auth 3.0.1 copy "corbado_auth: ^3.0.1" to clipboard
corbado_auth: ^3.0.1 copied to clipboard

Flutter package for Corbado Auth. Enables authentication on Android and iOS using passkeys.

example/lib/main.dart

import 'package:corbado_auth/corbado_auth.dart';
import 'package:corbado_auth_example/auth_provider.dart';
import 'package:corbado_auth_example/pages/loading_page.dart';
import 'package:corbado_auth_example/router.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:overlay_support/overlay_support.dart';

// In your own project you should get this from an ENV variable or from a Flutter flavour.
String calculateProjectID() {
  if (kIsWeb) {
    return 'pro-4268394291597054564';
  } else {
    return 'pro-4268394291597054564';
  }
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // This is a nice pattern if you need to initialize some of your services
  // before the app starts.
  // As we are using riverpod this initialization happens inside providers.
  // First we show a loading page.
  runApp(const LoadingPage());

  // Now we do the initialization.
  final projectId = calculateProjectID();
  final customDomain = 'https://$projectId.frontendapi.cloud.corbado.io';
  final corbadoAuth = CorbadoAuth();
  await corbadoAuth.init(projectId: projectId, customDomain: customDomain);

  // Finally we override the providers that needed initialization.
  // Now the real app can be loaded.
  runApp(ProviderScope(
    overrides: [
      corbadoProvider.overrideWithValue(corbadoAuth),
    ],
    child: const MyApp(),
  ));
}

class MyApp extends ConsumerWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final router = ref.watch(routerProvider);

    return OverlaySupport.global(
      child: MaterialApp.router(
        routeInformationParser: router.routeInformationParser,
        routerDelegate: router.routerDelegate,
        routeInformationProvider: router.routeInformationProvider,
        theme: ThemeData(
          useMaterial3: false,
          colorScheme: const ColorScheme(
            brightness: Brightness.light,
            primary: Color(0xFF1953ff),
            onPrimary: Colors.white,
            secondary: Colors.white,
            onSecondary: Color(0xFF1953ff),
            error: Colors.redAccent,
            onError: Colors.white,
            background: Color(0xFF1953ff),
            onBackground: Colors.white,
            surface: Color(0xFF1953ff),
            onSurface: Color(0xFF1953ff),
          ),
        ),
      ),
    );
  }
}
10
likes
130
points
298
downloads

Publisher

verified publishercorbado.com

Weekly Downloads

Flutter package for Corbado Auth. Enables authentication on Android and iOS using passkeys.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

built_collection, corbado_frontend_api_client, dio, flutter, flutter_keychain, http, json_annotation, jwt_decoder, meta, passkeys, rxdart, ua_client_hints, universal_html

More

Packages that depend on corbado_auth