flutter_heyteacher_auth 2.0.11+150 copy "flutter_heyteacher_auth: ^2.0.11+150" to clipboard
flutter_heyteacher_auth: ^2.0.11+150 copied to clipboard

The flutter heyteacher package for authentication utilities: UI widgets, stream, sign in and sign out

Flutter HeyTeacher Auth #

A Flutter package responsible for managing authentication within the HeyTeacher ecosystem.

This package provides the necessary utilities and repositories to handle user sessions, including Google Sign-In and a demo authentication mode.

Features #

  • Authentication Management: Handle user sign-in and sign-out flows using Firebase Authentication.
  • Google Sign-In: Integrated support for authenticating users via Google.
  • User Management: Utilities for managing user profiles and scheduling account deletion.
  • Demo Mode: Fake authentication support for demonstration and testing purposes without requiring real credentials with firebase_auth_mocks.
  • Ecosystem Integration: Designed to work seamlessly with other packages of flutter_heyteacher_packages

Usage #

Configure Firebase Authentication and link to your app following documentation firebase setup for app flutter project.

Add flutter_heyteacher_auth as a dependency in your pubspec.yaml file.

dependencies:
  flutter_heyteacher_auth: 

Import the package in your Dart code:

import 'package:flutter_heyteacher_auth/flutter_heyteacher_auth.dart';

In your main function, initialize auth

Future<void> main() async {
  // ensureInitialized
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

in your App widget, instanziate MaterialApp.router configuring router config with GoRoute

  Widget build(BuildContext context) => MaterialApp.router(
    .
    .
    ,
    localizationsDelegates: const [
      FlutterHeyteacherAuthLocalizations.delegate,
    ],
    routerConfig: GoRouter(
      routes: [
        GoRoute(
          path: '/',
          builder: (context, state) => const _MyHomePage(
            title: 'Your home page',
          ),
          routes: [
            GoAuthRoute.builder(
              landingRoutePath: '/'
            ),
          ],
        ),
      ],
    ),
  );

A complete app example can be found in example

Delete User Data #

User Data deletion is delegate to the application which uses flutter_heyteacher_auth.

In order to use Delete User Data feature you need:

  • in initialize enable delete user data:

    AuthViewModel.initialize(enableDeleteUserData: true);
    
  • in AccountCard set deleteAccountCallback and deleteAccountConfirmMessage

    AccountCard(
      deleteAccountConfirmMessage: 'Are you sure to delete your user data?',
      deleteAccountCallback: () async {
        // insert here your logic to delete user data
        showSnackBar(context: context, message: 'content');
      },
    ),
    

Mock Firestore Authentication #

In unit tests and example applications you can mock Firebase Authentication with firebase_auth_mocks:

  // Mock Firebase Authentication
  final mockFirebaseAuth = MockFirebaseAuth(
    mockUser: MockUser(
      uid: 'testuid',
      email: 'test@example.com',
      displayName: 'Test User',
    ),
  );
  //initialize Auth with MockFirebaseAuth
  AuthViewModel.instance = AuthViewModel(mockedFirebaseAuth: mockFirebaseAuth);