Skip to content

Commit

Permalink
feat: Move Supabase client initialization (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirland authored Oct 13, 2023
1 parent 1de6bfc commit 6cbb9eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 3 additions & 10 deletions supabase-ws-flutter-mobile/lib/core/di/app_providers_module.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_template/core/common/config.dart';
import 'package:flutter_template/core/source/common/local_shared_preferences_storage.dart';
import 'package:flutter_template/main.dart';
import 'package:get_it/get_it.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_template/core/source/common/local_shared_preferences_storage.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

class AppProvidersModule {
AppProvidersModule._privateConstructor();
Expand All @@ -21,7 +20,7 @@ class AppProvidersModule {

extension _GetItDiModuleExtensions on GetIt {
void _setupModule() {
registerSingletonAsync(_initSupabase);
registerSingletonAsync(initSupabase);
registerLazySingleton(FlutterSecureStorage.new);
registerSingletonAsync(() => SharedPreferences.getInstance());

Expand All @@ -33,9 +32,3 @@ extension _GetItDiModuleExtensions on GetIt {
);
}
}

//TODO: Discuss where we should initialize it
Future<SupabaseClient> _initSupabase() => Supabase.initialize(
url: Config.apiBaseUrl,
anonKey: Config.supabaseApiKey,
).then((supabase) => supabase.client);
8 changes: 8 additions & 0 deletions supabase-ws-flutter-mobile/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import 'package:flutter_template/core/common/config.dart';
import 'package:flutter_template/core/common/logger.dart';
import 'package:flutter_template/core/di/di_provider.dart';
import 'package:flutter_template/ui/main/main_screen.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

// This should be initialized in `AppProvidersModule` but it's here just for
// the example.
Future<SupabaseClient> initSupabase() => Supabase.initialize(
url: Config.apiBaseUrl,
anonKey: Config.supabaseApiKey,
).then((supabase) => supabase.client);

Future main() async {
await runZonedGuarded(
Expand Down

0 comments on commit 6cbb9eb

Please sign in to comment.