From 6ce695abb9ff89a3db31644bac5d34711c5b1abc Mon Sep 17 00:00:00 2001 From: Daniel Mossaband Date: Mon, 7 Mar 2022 18:29:03 -0800 Subject: [PATCH 1/7] chore: update packages --- lib/src/local_storage.dart | 31 ++++++++++++++++--------------- pubspec.lock | 8 ++++---- pubspec.yaml | 6 +++--- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/src/local_storage.dart b/lib/src/local_storage.dart index 8dda3afe..bd645524 100644 --- a/lib/src/local_storage.dart +++ b/lib/src/local_storage.dart @@ -10,7 +10,7 @@ const supabasePersistSessionKey = 'SUPABASE_PERSIST_SESSION_KEY'; /// See also: /// /// * [SupabaseAuth], the instance used to manage authentication -/// * [EmptyLocalStorage], used to disable session persistance +/// * [EmptyLocalStorage], used to disable session persistence /// * [HiveLocalStorage], that implements Hive as storage method abstract class LocalStorage { const LocalStorage({ @@ -38,17 +38,17 @@ abstract class LocalStorage { } /// A [LocalStorage] implementation that does nothing. Use this to -/// disable persistance. +/// disable persistence. class EmptyLocalStorage extends LocalStorage { - /// Creates a [LocalStorage] instance that disables persistance + /// Creates a [LocalStorage] instance that disables persistence const EmptyLocalStorage() : super( - initialize: _initialize, - hasAccessToken: _hasAccessToken, - accessToken: _accessToken, - removePersistedSession: _removePersistedSession, - persistSession: _persistSession, - ); + initialize: _initialize, + hasAccessToken: _hasAccessToken, + accessToken: _accessToken, + removePersistedSession: _removePersistedSession, + persistSession: _persistSession, + ); static Future _initialize() async {} static Future _hasAccessToken() => Future.value(false); @@ -63,12 +63,12 @@ class HiveLocalStorage extends LocalStorage { /// Creates a LocalStorage instance that implements the Hive Database const HiveLocalStorage() : super( - initialize: _initialize, - hasAccessToken: _hasAccessToken, - accessToken: _accessToken, - removePersistedSession: _removePersistedSession, - persistSession: _persistSession, - ); + initialize: _initialize, + hasAccessToken: _hasAccessToken, + accessToken: _accessToken, + removePersistedSession: _removePersistedSession, + persistSession: _persistSession, + ); /// The encryption key used by Hive. If null, the box is not encrypted /// @@ -104,6 +104,7 @@ class HiveLocalStorage extends LocalStorage { } static Future _persistSession(String persistSessionString) { + // Flush after X amount of writes return Hive.box(_hiveBoxName) .put(supabasePersistSessionKey, persistSessionString); } diff --git a/pubspec.lock b/pubspec.lock index 5b1d86a9..ddd37806 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -92,14 +92,14 @@ packages: name: gotrue url: "https://pub.dartlang.org" source: hosted - version: "0.1.5" + version: "0.1.6" hive: dependency: "direct main" description: name: hive url: "https://pub.dartlang.org" source: hosted - version: "2.0.4" + version: "2.0.6" hive_flutter: dependency: "direct main" description: @@ -293,7 +293,7 @@ packages: name: supabase url: "https://pub.dartlang.org" source: hosted - version: "0.2.14" + version: "0.2.15" term_glyph: dependency: transitive description: @@ -349,7 +349,7 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "6.0.9" + version: "6.0.10" url_launcher_linux: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index b2173a8f..bba1e012 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,11 +11,11 @@ environment: dependencies: flutter: sdk: flutter - hive: ^2.0.4 + hive: ^2.0.6 hive_flutter: ^1.1.0 - supabase: ^0.2.14 + supabase: ^0.2.15 uni_links: ^0.5.1 - url_launcher: ^6.0.9 + url_launcher: ^6.0.10 dev_dependencies: flutter_test: From 10f352ef233d7a60302ee44ba5988cf5a0a59712 Mon Sep 17 00:00:00 2001 From: Daniel Mossaband Date: Mon, 7 Mar 2022 18:30:58 -0800 Subject: [PATCH 2/7] Format code nicely --- lib/src/local_storage.dart | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/src/local_storage.dart b/lib/src/local_storage.dart index bd645524..9ee505a7 100644 --- a/lib/src/local_storage.dart +++ b/lib/src/local_storage.dart @@ -43,12 +43,12 @@ class EmptyLocalStorage extends LocalStorage { /// Creates a [LocalStorage] instance that disables persistence const EmptyLocalStorage() : super( - initialize: _initialize, - hasAccessToken: _hasAccessToken, - accessToken: _accessToken, - removePersistedSession: _removePersistedSession, - persistSession: _persistSession, - ); + initialize: _initialize, + hasAccessToken: _hasAccessToken, + accessToken: _accessToken, + removePersistedSession: _removePersistedSession, + persistSession: _persistSession, + ); static Future _initialize() async {} static Future _hasAccessToken() => Future.value(false); @@ -63,12 +63,12 @@ class HiveLocalStorage extends LocalStorage { /// Creates a LocalStorage instance that implements the Hive Database const HiveLocalStorage() : super( - initialize: _initialize, - hasAccessToken: _hasAccessToken, - accessToken: _accessToken, - removePersistedSession: _removePersistedSession, - persistSession: _persistSession, - ); + initialize: _initialize, + hasAccessToken: _hasAccessToken, + accessToken: _accessToken, + removePersistedSession: _removePersistedSession, + persistSession: _persistSession, + ); /// The encryption key used by Hive. If null, the box is not encrypted /// From 103a4040512b75d637ad2ed39d2465fbc8791235 Mon Sep 17 00:00:00 2001 From: Daniel Mossaband Date: Mon, 14 Mar 2022 09:22:51 -0700 Subject: [PATCH 3/7] Fix dependency errors --- pubspec.lock | 98 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 35 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index ddd37806..c3b3cf5d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.8.2" boolean_selector: dependency: transitive description: @@ -21,14 +21,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -113,7 +113,7 @@ packages: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.13.3" + version: "0.13.4" http_parser: dependency: transitive description: @@ -141,28 +141,35 @@ packages: name: lint url: "https://pub.dartlang.org" source: hosted - version: "1.5.3" + version: "1.8.2" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.11" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.3" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" mime: dependency: transitive description: name: mime url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.0.1" path: dependency: transitive description: @@ -176,56 +183,63 @@ packages: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.0.9" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.12" + path_provider_ios: + dependency: transitive + description: + name: path_provider_ios + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.8" path_provider_linux: dependency: transitive description: name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.5" path_provider_macos: dependency: transitive description: name: path_provider_macos url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.0.5" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.3" path_provider_windows: dependency: transitive description: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.11.1" + version: "2.0.5" platform: dependency: transitive description: name: platform url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.1.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.2" postgrest: dependency: transitive description: @@ -239,7 +253,7 @@ packages: name: process url: "https://pub.dartlang.org" source: hosted - version: "4.2.1" + version: "4.2.4" realtime_client: dependency: transitive description: @@ -307,7 +321,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.4.8" typed_data: dependency: transitive description: @@ -349,49 +363,63 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "6.0.10" + version: "6.0.20" + url_launcher_android: + dependency: transitive + description: + name: url_launcher_android + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.15" + url_launcher_ios: + dependency: transitive + description: + name: url_launcher_ios + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.15" url_launcher_linux: dependency: transitive description: name: url_launcher_linux url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "3.0.0" url_launcher_macos: dependency: transitive description: name: url_launcher_macos url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "3.0.0" url_launcher_platform_interface: dependency: transitive description: name: url_launcher_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.4" + version: "2.0.5" url_launcher_web: dependency: transitive description: name: url_launcher_web url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.9" url_launcher_windows: dependency: transitive description: name: url_launcher_windows url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "3.0.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" web_socket_channel: dependency: transitive description: @@ -405,14 +433,14 @@ packages: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.2.4" + version: "2.4.1" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "0.2.0" + version: "0.2.0+1" sdks: - dart: ">=2.13.0 <3.0.0" - flutter: ">=2.0.0" + dart: ">=2.15.0 <3.0.0" + flutter: ">=2.10.0" From 6a84b7b1d13fa54913d5ca4085f6ba9a907a2a70 Mon Sep 17 00:00:00 2001 From: Daniel Mossaband Date: Mon, 14 Mar 2022 14:34:53 -0700 Subject: [PATCH 4/7] Fix lint errors --- lib/src/local_storage.dart | 9 +++------ lib/src/supabase.dart | 4 ++-- lib/src/supabase_auth.dart | 12 ++++-------- lib/src/supabase_auth_required_state.dart | 17 +++++++---------- lib/src/supabase_auth_state.dart | 15 ++++++--------- lib/src/supabase_deep_linking_mixin.dart | 23 +++++++++++++---------- test/supabase_flutter_test.dart | 9 ++++++--- test/widget_test_stubs.dart | 15 ++++++++------- 8 files changed, 49 insertions(+), 55 deletions(-) diff --git a/lib/src/local_storage.dart b/lib/src/local_storage.dart index 9ee505a7..3a1a1513 100644 --- a/lib/src/local_storage.dart +++ b/lib/src/local_storage.dart @@ -90,13 +90,11 @@ class HiveLocalStorage extends LocalStorage { } static Future _hasAccessToken() { - return Future.value( - Hive.box(_hiveBoxName).containsKey(supabasePersistSessionKey)); + return Future.value(Hive.box(_hiveBoxName).containsKey(supabasePersistSessionKey)); } static Future _accessToken() { - return Future.value( - Hive.box(_hiveBoxName).get(supabasePersistSessionKey) as String?); + return Future.value(Hive.box(_hiveBoxName).get(supabasePersistSessionKey) as String?); } static Future _removePersistedSession() { @@ -105,7 +103,6 @@ class HiveLocalStorage extends LocalStorage { static Future _persistSession(String persistSessionString) { // Flush after X amount of writes - return Hive.box(_hiveBoxName) - .put(supabasePersistSessionKey, persistSessionString); + return Hive.box(_hiveBoxName).put(supabasePersistSessionKey, persistSessionString); } } diff --git a/lib/src/supabase.dart b/lib/src/supabase.dart index 62d3e51f..9c490746 100644 --- a/lib/src/supabase.dart +++ b/lib/src/supabase.dart @@ -1,8 +1,8 @@ import 'package:flutter/foundation.dart'; import 'package:supabase/supabase.dart'; -import 'local_storage.dart'; -import 'supabase_auth.dart'; +import 'package:supabase_flutter/src/local_storage.dart'; +import 'package:supabase_flutter/src/supabase_auth.dart'; /// Supabase instance. /// diff --git a/lib/src/supabase_auth.dart b/lib/src/supabase_auth.dart index d0641cd1..f3835b42 100644 --- a/lib/src/supabase_auth.dart +++ b/lib/src/supabase_auth.dart @@ -1,9 +1,8 @@ import 'dart:async'; +import 'package:supabase_flutter/supabase_flutter.dart'; import 'package:url_launcher/url_launcher.dart'; -import '../supabase_flutter.dart'; - /// SupabaseAuth class SupabaseAuth { SupabaseAuth._(); @@ -66,8 +65,7 @@ class SupabaseAuth { _instance._localStorage = localStorage; _instance._authCallbackUrlHostname = authCallbackUrlHostname; - _instance._authSubscription = - Supabase.instance.client.auth.onAuthStateChange((event, session) { + _instance._authSubscription = Supabase.instance.client.auth.onAuthStateChange((event, session) { _instance._onAuthStateChange(event, session); if (!_instance._listenerController.isClosed) { _instance._listenerController.add(event); @@ -80,8 +78,7 @@ class SupabaseAuth { if (hasPersistedSession) { final persistedSession = await _instance._localStorage.accessToken(); if (persistedSession != null) { - final response = await Supabase.instance.client.auth - .recoverSession(persistedSession); + final response = await Supabase.instance.client.auth.recoverSession(persistedSession); if (response.error != null) { Supabase.instance.log(response.error!.message); @@ -159,8 +156,7 @@ extension GoTrueClientSignInProvider on GoTrueClient { /// See also: /// /// * - Future signInWithProvider(Provider provider, - {AuthOptions? options}) async { + Future signInWithProvider(Provider provider, {AuthOptions? options}) async { final res = await signIn( provider: provider, options: options, diff --git a/lib/src/supabase_auth_required_state.dart b/lib/src/supabase_auth_required_state.dart index 35987747..aa8b2a0c 100644 --- a/lib/src/supabase_auth_required_state.dart +++ b/lib/src/supabase_auth_required_state.dart @@ -1,13 +1,13 @@ import 'dart:async'; import 'package:flutter/widgets.dart'; +import 'package:supabase_flutter/src/supabase_state.dart'; -import '../supabase_flutter.dart'; -import 'supabase_state.dart'; +import 'package:supabase_flutter/supabase_flutter.dart'; /// Interface for screen that requires an authenticated user -abstract class SupabaseAuthRequiredState - extends SupabaseState with WidgetsBindingObserver { +abstract class SupabaseAuthRequiredState extends SupabaseState + with WidgetsBindingObserver { late final StreamSubscription _authStateListener; @override @@ -66,22 +66,19 @@ abstract class SupabaseAuthRequiredState } Future _recoverSupabaseSession() async { - final bool exist = - await SupabaseAuth.instance.localStorage.hasAccessToken(); + final bool exist = await SupabaseAuth.instance.localStorage.hasAccessToken(); if (!exist) { onUnauthenticated(); return false; } - final String? jsonStr = - await SupabaseAuth.instance.localStorage.accessToken(); + final String? jsonStr = await SupabaseAuth.instance.localStorage.accessToken(); if (jsonStr == null) { onUnauthenticated(); return false; } - final response = - await Supabase.instance.client.auth.recoverSession(jsonStr); + final response = await Supabase.instance.client.auth.recoverSession(jsonStr); if (response.error != null) { SupabaseAuth.instance.localStorage.removePersistedSession(); onUnauthenticated(); diff --git a/lib/src/supabase_auth_state.dart b/lib/src/supabase_auth_state.dart index 323f3b43..2367828b 100644 --- a/lib/src/supabase_auth_state.dart +++ b/lib/src/supabase_auth_state.dart @@ -4,12 +4,12 @@ import 'package:flutter/widgets.dart'; import 'package:supabase_flutter/src/supabase_deep_linking_mixin.dart'; import 'package:supabase_flutter/src/supabase_state.dart'; -import '../supabase_flutter.dart'; +import 'package:supabase_flutter/supabase_flutter.dart'; /// Interface for user authentication screen /// It supports deeplink authentication -abstract class SupabaseAuthState - extends SupabaseState with SupabaseDeepLinkingMixin { +abstract class SupabaseAuthState extends SupabaseState + with SupabaseDeepLinkingMixin { @override void startAuthObserver() { Supabase.instance.log('***** SupabaseAuthState startAuthObserver'); @@ -78,22 +78,19 @@ abstract class SupabaseAuthState /// Recover/refresh session if it's available /// e.g. called on a Splash screen when app starts. Future recoverSupabaseSession() async { - final bool exist = - await SupabaseAuth.instance.localStorage.hasAccessToken(); + final bool exist = await SupabaseAuth.instance.localStorage.hasAccessToken(); if (!exist) { onUnauthenticated(); return false; } - final String? jsonStr = - await SupabaseAuth.instance.localStorage.accessToken(); + final String? jsonStr = await SupabaseAuth.instance.localStorage.accessToken(); if (jsonStr == null) { onUnauthenticated(); return false; } - final response = - await Supabase.instance.client.auth.recoverSession(jsonStr); + final response = await Supabase.instance.client.auth.recoverSession(jsonStr); if (response.error != null) { SupabaseAuth.instance.localStorage.removePersistedSession(); onUnauthenticated(); diff --git a/lib/src/supabase_deep_linking_mixin.dart b/lib/src/supabase_deep_linking_mixin.dart index 3cb8e4c9..18f89cae 100644 --- a/lib/src/supabase_deep_linking_mixin.dart +++ b/lib/src/supabase_deep_linking_mixin.dart @@ -3,9 +3,9 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; -import 'package:uni_links/uni_links.dart'; -import '../supabase_flutter.dart'; +import 'package:supabase_flutter/supabase_flutter.dart'; +import 'package:uni_links/uni_links.dart'; mixin SupabaseDeepLinkingMixin on State { StreamSubscription? _sub; @@ -27,14 +27,17 @@ mixin SupabaseDeepLinkingMixin on State { if (!kIsWeb) { // It will handle app links while the app is already started - be it in // the foreground or in the background. - _sub = uriLinkStream.listen((Uri? uri) { - if (mounted && uri != null) { - handleDeeplink(uri); - } - }, onError: (Object err) { - if (!mounted) return; - onErrorReceivingDeeplink(err.toString()); - }); + _sub = uriLinkStream.listen( + (Uri? uri) { + if (mounted && uri != null) { + handleDeeplink(uri); + } + }, + onError: (Object err) { + if (!mounted) return; + onErrorReceivingDeeplink(err.toString()); + }, + ); } } diff --git a/test/supabase_flutter_test.dart b/test/supabase_flutter_test.dart index adc26fa9..652c4bc7 100644 --- a/test/supabase_flutter_test.dart +++ b/test/supabase_flutter_test.dart @@ -18,7 +18,8 @@ void main() { test('can parse deeplink', () async { final uri = Uri.parse( - "io.supabase.flutterdemo://login-callback#access_token=aaa&expires_in=3600&refresh_token=bbb&token_type=bearer&type=recovery"); + "io.supabase.flutterdemo://login-callback#access_token=aaa&expires_in=3600&refresh_token=bbb&token_type=bearer&type=recovery", + ); final uriParams = SupabaseAuth.instance.parseUriParameters(uri); expect(uriParams.length, equals(5)); expect(uriParams['access_token'], equals('aaa')); @@ -27,7 +28,8 @@ void main() { test('can parse flutter web redirect link', () async { final uri = Uri.parse( - "http://localhost:55510/#access_token=aaa&expires_in=3600&refresh_token=bbb&token_type=bearer&type=magiclink"); + "http://localhost:55510/#access_token=aaa&expires_in=3600&refresh_token=bbb&token_type=bearer&type=magiclink", + ); final uriParams = SupabaseAuth.instance.parseUriParameters(uri); expect(uriParams.length, equals(5)); expect(uriParams['access_token'], equals('aaa')); @@ -36,7 +38,8 @@ void main() { test('can parse flutter web custom page redirect link', () async { final uri = Uri.parse( - "http://localhost:55510/#/webAuth%23access_token=aaa&expires_in=3600&refresh_token=bbb&token_type=bearer&type=magiclink"); + "http://localhost:55510/#/webAuth%23access_token=aaa&expires_in=3600&refresh_token=bbb&token_type=bearer&type=magiclink", + ); final uriParams = SupabaseAuth.instance.parseUriParameters(uri); expect(uriParams.length, equals(5)); expect(uriParams['access_token'], equals('aaa')); diff --git a/test/widget_test_stubs.dart b/test/widget_test_stubs.dart index 65f8d772..b4b56a08 100644 --- a/test/widget_test_stubs.dart +++ b/test/widget_test_stubs.dart @@ -34,12 +34,13 @@ class _MockWidgetState extends SupabaseAuthRequiredState { class MockLocalStorage extends LocalStorage { MockLocalStorage() : super( - initialize: () async {}, + initialize: () async {}, - /// Session expires at is at its maximum value for unix timestamp - accessToken: () async => - '{"currentSession":{"access_token":"","expires_in":3600,"refresh_token":"","user":{"id":"","aud":"","created_at":"","role":"authenticated","updated_at":""}},"expiresAt":2147483647}', - persistSession: (_) async {}, - removePersistedSession: () async {}, - hasAccessToken: () async => true); + /// Session expires at is at its maximum value for unix timestamp + accessToken: () async => + '{"currentSession":{"access_token":"","expires_in":3600,"refresh_token":"","user":{"id":"","aud":"","created_at":"","role":"authenticated","updated_at":""}},"expiresAt":2147483647}', + persistSession: (_) async {}, + removePersistedSession: () async {}, + hasAccessToken: () async => true, + ); } From 80fb1e1c25420b94b1676c8ee4ac966cba786c52 Mon Sep 17 00:00:00 2001 From: Daniel Mossaband Date: Wed, 16 Mar 2022 10:44:30 -0700 Subject: [PATCH 5/7] Fix formatting --- lib/src/local_storage.dart | 9 ++++++--- lib/src/supabase_auth.dart | 9 ++++++--- lib/src/supabase_auth_required_state.dart | 13 ++++++++----- lib/src/supabase_auth_state.dart | 13 ++++++++----- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/lib/src/local_storage.dart b/lib/src/local_storage.dart index 3a1a1513..9ee505a7 100644 --- a/lib/src/local_storage.dart +++ b/lib/src/local_storage.dart @@ -90,11 +90,13 @@ class HiveLocalStorage extends LocalStorage { } static Future _hasAccessToken() { - return Future.value(Hive.box(_hiveBoxName).containsKey(supabasePersistSessionKey)); + return Future.value( + Hive.box(_hiveBoxName).containsKey(supabasePersistSessionKey)); } static Future _accessToken() { - return Future.value(Hive.box(_hiveBoxName).get(supabasePersistSessionKey) as String?); + return Future.value( + Hive.box(_hiveBoxName).get(supabasePersistSessionKey) as String?); } static Future _removePersistedSession() { @@ -103,6 +105,7 @@ class HiveLocalStorage extends LocalStorage { static Future _persistSession(String persistSessionString) { // Flush after X amount of writes - return Hive.box(_hiveBoxName).put(supabasePersistSessionKey, persistSessionString); + return Hive.box(_hiveBoxName) + .put(supabasePersistSessionKey, persistSessionString); } } diff --git a/lib/src/supabase_auth.dart b/lib/src/supabase_auth.dart index f3835b42..d0fab078 100644 --- a/lib/src/supabase_auth.dart +++ b/lib/src/supabase_auth.dart @@ -65,7 +65,8 @@ class SupabaseAuth { _instance._localStorage = localStorage; _instance._authCallbackUrlHostname = authCallbackUrlHostname; - _instance._authSubscription = Supabase.instance.client.auth.onAuthStateChange((event, session) { + _instance._authSubscription = + Supabase.instance.client.auth.onAuthStateChange((event, session) { _instance._onAuthStateChange(event, session); if (!_instance._listenerController.isClosed) { _instance._listenerController.add(event); @@ -78,7 +79,8 @@ class SupabaseAuth { if (hasPersistedSession) { final persistedSession = await _instance._localStorage.accessToken(); if (persistedSession != null) { - final response = await Supabase.instance.client.auth.recoverSession(persistedSession); + final response = await Supabase.instance.client.auth + .recoverSession(persistedSession); if (response.error != null) { Supabase.instance.log(response.error!.message); @@ -156,7 +158,8 @@ extension GoTrueClientSignInProvider on GoTrueClient { /// See also: /// /// * - Future signInWithProvider(Provider provider, {AuthOptions? options}) async { + Future signInWithProvider(Provider provider, + {AuthOptions? options}) async { final res = await signIn( provider: provider, options: options, diff --git a/lib/src/supabase_auth_required_state.dart b/lib/src/supabase_auth_required_state.dart index aa8b2a0c..f88448a1 100644 --- a/lib/src/supabase_auth_required_state.dart +++ b/lib/src/supabase_auth_required_state.dart @@ -6,8 +6,8 @@ import 'package:supabase_flutter/src/supabase_state.dart'; import 'package:supabase_flutter/supabase_flutter.dart'; /// Interface for screen that requires an authenticated user -abstract class SupabaseAuthRequiredState extends SupabaseState - with WidgetsBindingObserver { +abstract class SupabaseAuthRequiredState + extends SupabaseState with WidgetsBindingObserver { late final StreamSubscription _authStateListener; @override @@ -66,19 +66,22 @@ abstract class SupabaseAuthRequiredState extends Supab } Future _recoverSupabaseSession() async { - final bool exist = await SupabaseAuth.instance.localStorage.hasAccessToken(); + final bool exist = + await SupabaseAuth.instance.localStorage.hasAccessToken(); if (!exist) { onUnauthenticated(); return false; } - final String? jsonStr = await SupabaseAuth.instance.localStorage.accessToken(); + final String? jsonStr = + await SupabaseAuth.instance.localStorage.accessToken(); if (jsonStr == null) { onUnauthenticated(); return false; } - final response = await Supabase.instance.client.auth.recoverSession(jsonStr); + final response = + await Supabase.instance.client.auth.recoverSession(jsonStr); if (response.error != null) { SupabaseAuth.instance.localStorage.removePersistedSession(); onUnauthenticated(); diff --git a/lib/src/supabase_auth_state.dart b/lib/src/supabase_auth_state.dart index 2367828b..163f3aba 100644 --- a/lib/src/supabase_auth_state.dart +++ b/lib/src/supabase_auth_state.dart @@ -8,8 +8,8 @@ import 'package:supabase_flutter/supabase_flutter.dart'; /// Interface for user authentication screen /// It supports deeplink authentication -abstract class SupabaseAuthState extends SupabaseState - with SupabaseDeepLinkingMixin { +abstract class SupabaseAuthState + extends SupabaseState with SupabaseDeepLinkingMixin { @override void startAuthObserver() { Supabase.instance.log('***** SupabaseAuthState startAuthObserver'); @@ -78,19 +78,22 @@ abstract class SupabaseAuthState extends SupabaseState /// Recover/refresh session if it's available /// e.g. called on a Splash screen when app starts. Future recoverSupabaseSession() async { - final bool exist = await SupabaseAuth.instance.localStorage.hasAccessToken(); + final bool exist = + await SupabaseAuth.instance.localStorage.hasAccessToken(); if (!exist) { onUnauthenticated(); return false; } - final String? jsonStr = await SupabaseAuth.instance.localStorage.accessToken(); + final String? jsonStr = + await SupabaseAuth.instance.localStorage.accessToken(); if (jsonStr == null) { onUnauthenticated(); return false; } - final response = await Supabase.instance.client.auth.recoverSession(jsonStr); + final response = + await Supabase.instance.client.auth.recoverSession(jsonStr); if (response.error != null) { SupabaseAuth.instance.localStorage.removePersistedSession(); onUnauthenticated(); From 339de6eddbed70a972b216a07f9a64f55cddcc2b Mon Sep 17 00:00:00 2001 From: Daniel Mossaband Date: Wed, 30 Mar 2022 13:50:16 -0700 Subject: [PATCH 6/7] chore: publish 0.3.0 --- CHANGELOG.md | 4 +++ pubspec.lock | 84 ++++++++++++++++++---------------------------------- pubspec.yaml | 2 +- 3 files changed, 33 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79126905..14e7da5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.3.0] + +- BREAKING: update gotrue_client to [v0.2.0](https://github.com/supabase-community/gotrue-dart/blob/main/CHANGELOG.md#020) + ## [0.2.12] - chore: update supabase-dart package v0.2.14 diff --git a/pubspec.lock b/pubspec.lock index c3b3cf5d..4ec15fb3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.6.1" boolean_selector: dependency: transitive description: @@ -21,14 +21,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.3.1" + version: "1.2.0" clock: dependency: transitive description: @@ -92,7 +92,7 @@ packages: name: gotrue url: "https://pub.dartlang.org" source: hosted - version: "0.1.6" + version: "0.2.0" hive: dependency: "direct main" description: @@ -113,7 +113,7 @@ packages: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.13.4" + version: "0.13.3" http_parser: dependency: transitive description: @@ -141,28 +141,21 @@ packages: name: lint url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.6.0" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.3" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.3.0" mime: dependency: transitive description: @@ -183,21 +176,7 @@ packages: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "2.0.9" - path_provider_android: - dependency: transitive - description: - name: path_provider_android - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.12" - path_provider_ios: - dependency: transitive - description: - name: path_provider_ios - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.8" + version: "2.0.4" path_provider_linux: dependency: transitive description: @@ -226,6 +205,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.5" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.11.1" platform: dependency: transitive description: @@ -253,7 +239,7 @@ packages: name: process url: "https://pub.dartlang.org" source: hosted - version: "4.2.4" + version: "4.2.3" realtime_client: dependency: transitive description: @@ -307,7 +293,7 @@ packages: name: supabase url: "https://pub.dartlang.org" source: hosted - version: "0.2.15" + version: "0.3.0" term_glyph: dependency: transitive description: @@ -321,7 +307,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.8" + version: "0.3.0" typed_data: dependency: transitive description: @@ -363,35 +349,21 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "6.0.20" - url_launcher_android: - dependency: transitive - description: - name: url_launcher_android - url: "https://pub.dartlang.org" - source: hosted - version: "6.0.15" - url_launcher_ios: - dependency: transitive - description: - name: url_launcher_ios - url: "https://pub.dartlang.org" - source: hosted - version: "6.0.15" + version: "6.0.10" url_launcher_linux: dependency: transitive description: name: url_launcher_linux url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "2.0.3" url_launcher_macos: dependency: transitive description: name: url_launcher_macos url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "2.0.3" url_launcher_platform_interface: dependency: transitive description: @@ -405,21 +377,21 @@ packages: name: url_launcher_web url: "https://pub.dartlang.org" source: hosted - version: "2.0.9" + version: "2.0.7" url_launcher_windows: dependency: transitive description: name: url_launcher_windows url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "2.0.2" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.0" web_socket_channel: dependency: transitive description: @@ -433,7 +405,7 @@ packages: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.4.1" + version: "2.2.10" xdg_directories: dependency: transitive description: @@ -442,5 +414,5 @@ packages: source: hosted version: "0.2.0+1" sdks: - dart: ">=2.15.0 <3.0.0" - flutter: ">=2.10.0" + dart: ">=2.13.0 <3.0.0" + flutter: ">=2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index bba1e012..590272f7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: sdk: flutter hive: ^2.0.6 hive_flutter: ^1.1.0 - supabase: ^0.2.15 + supabase: ^0.3.0 uni_links: ^0.5.1 url_launcher: ^6.0.10 From 24a2e4f07b6bf107c73300804635b99ee35333f7 Mon Sep 17 00:00:00 2001 From: Daniel Mossaband Date: Wed, 30 Mar 2022 13:52:02 -0700 Subject: [PATCH 7/7] Update readme --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14e7da5f..d58e922a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## [0.3.0] -- BREAKING: update gotrue_client to [v0.2.0](https://github.com/supabase-community/gotrue-dart/blob/main/CHANGELOG.md#020) +- BREAKING: update supabase to [v0.3.0](https://github.com/supabase-community/supabase-dart/blob/main/CHANGELOG.md#030) ## [0.2.12]