Skip to content

Commit

Permalink
Merge branch 'supabase-community-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
sunegg committed Apr 24, 2022
2 parents 4f48e18 + f36b407 commit 78c5fcc
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 54 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [0.3.0]

- BREAKING: update supabase to [v0.3.0](https://github.com/supabase-community/supabase-dart/blob/main/CHANGELOG.md#030)

## [0.2.12]

- chore: update supabase-dart package v0.2.14
Expand Down
7 changes: 4 additions & 3 deletions lib/src/local_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -38,9 +38,9 @@ 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,
Expand Down Expand Up @@ -104,6 +104,7 @@ class HiveLocalStorage extends LocalStorage {
}

static Future<void> _persistSession(String persistSessionString) {
// Flush after X amount of writes
return Hive.box(_hiveBoxName)
.put(supabasePersistSessionKey, persistSessionString);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/supabase.dart
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down
3 changes: 1 addition & 2 deletions lib/src/supabase_auth.dart
Original file line number Diff line number Diff line change
@@ -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._();
Expand Down
4 changes: 2 additions & 2 deletions lib/src/supabase_auth_required_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'dart:async';

import 'package:flutter/widgets.dart';
import 'package:flutter_riverpod/flutter_riverpod.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<T extends ConsumerStatefulWidget>
Expand Down
2 changes: 1 addition & 1 deletion lib/src/supabase_auth_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.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
Expand Down
22 changes: 12 additions & 10 deletions lib/src/supabase_deep_linking_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:uni_links/uni_links.dart';

import '../supabase_flutter.dart';

mixin SupabaseDeepLinkingMixin<T extends ConsumerStatefulWidget>
on ConsumerState<T> {
StreamSubscription? _sub;
Expand All @@ -28,14 +27,17 @@ mixin SupabaseDeepLinkingMixin<T extends ConsumerStatefulWidget>
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());
},
);
}
}

Expand Down
42 changes: 21 additions & 21 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ packages:
name: gotrue
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5"
version: "0.2.0"
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:
Expand Down Expand Up @@ -148,7 +148,7 @@ packages:
name: lint
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.3"
version: "1.6.0"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -176,7 +176,7 @@ packages:
name: mime
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.0.1"
path:
dependency: transitive
description:
Expand All @@ -190,35 +190,35 @@ packages:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.0.4"
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"
version: "2.0.5"
pedantic:
dependency: transitive
description:
Expand All @@ -232,14 +232,14 @@ packages:
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:
Expand All @@ -253,7 +253,7 @@ packages:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.1"
version: "4.2.3"
realtime_client:
dependency: transitive
description:
Expand Down Expand Up @@ -321,7 +321,7 @@ packages:
name: supabase
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.14"
version: "0.3.0"
term_glyph:
dependency: transitive
description:
Expand Down Expand Up @@ -377,42 +377,42 @@ 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:
name: url_launcher_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.0.3"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.0.3"
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.7"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.0.2"
vector_math:
dependency: transitive
description:
Expand All @@ -433,14 +433,14 @@ packages:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.4"
version: "2.2.10"
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.14.0 <3.0.0"
flutter: ">=2.0.0"
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ environment:
dependencies:
flutter:
sdk: flutter
hive: ^2.0.4
hive: ^2.0.6
hive_flutter: ^1.1.0
flutter_riverpod: ^1.0.3
supabase: ^0.2.14
supabase: ^0.3.0
uni_links: ^0.5.1
url_launcher: ^6.0.9
url_launcher: ^6.0.10

dev_dependencies:
flutter_test:
Expand Down
9 changes: 6 additions & 3 deletions test/supabase_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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'));
Expand All @@ -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'));
Expand Down
15 changes: 8 additions & 7 deletions test/widget_test_stubs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ class _MockWidgetState extends SupabaseAuthRequiredState<MockWidget> {
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,
);
}

0 comments on commit 78c5fcc

Please sign in to comment.