Skip to content

Commit

Permalink
Merge pull request supabase#159 from dshukertjr/BREAKING/rework
Browse files Browse the repository at this point in the history
chore: publish v1.0.0-dev.1
  • Loading branch information
dshukertjr committed Aug 1, 2022
2 parents 50d532e + b2c2f90 commit b2a89a9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
flutter-version: ['2.5.0', '2.10.5', '3.x']
flutter-version: ['3.x']

runs-on: ${{ matrix.os }}

Expand Down
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
## [1.0.0-dev.1]
- feat: add Mac OS and Windows support for deeplinks
- BREAKING: Remove SupabaseAuthRequiredState as well as overriding methods in SupabaseAuthState
```dart
// Before
await Supabase.initialize(
url: 'SUPABASE_URL',
anonKey: 'SUPABASE_ANON_KEY',
);
...
// Class extending `SupabaseAuthState` or `AuthRequiredState` was necessary
// to persist auth state
class AuthState<T extends StatefulWidget> extends SupabaseAuthState<T> {
...
}
// After
// Initializing Supabase is all you need to do to persist auth state
// Deeplinks will also be automatically handled when you initialize Supabase.
await Supabase.initialize(
url: 'SUPABASE_URL',
anonKey: 'SUPABASE_ANON_KEY',
);
...
// You can get the initial session of the user with `SupabaseAuth.instance.initialSession`
try {
final initialSession = await SupabaseAuth.instance.initialSession;
} catch(error) {
// Handle errors in session initial recovery here
}
// You should now use `onAuthStateChanged` as the
Supabase.instance.client.auth.onAuthStateChange((event, session) {
// handle sinin/ signups here
});
```
- fix: OAuth should open in an external browser
- BREAKING: update supabase package [v1.0.0-dev.1](https://github.com/supabase-community/supabase-dart/blob/main/CHANGELOG.md#100-dev1)

## [0.3.3]
- feat: update supabase package [v0.3.6](https://github.com/supabase-community/supabase-dart/blob/main/CHANGELOG.md#036)

Expand Down
40 changes: 23 additions & 17 deletions lib/src/supabase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,22 @@ class SupabaseAuth with WidgetsBindingObserver {
if (hasPersistedSession) {
final persistedSession = await _instance._localStorage.accessToken();
if (persistedSession != null) {
final response = await Supabase.instance.client.auth
.recoverSession(persistedSession);
final error = response.error;

if (error != null) {
Supabase.instance.log(response.error!.message);
try {
final response = await Supabase.instance.client.auth
.recoverSession(persistedSession);
if (!_instance._initialSessionCompleter.isCompleted) {
_instance._initialSessionCompleter.complete(response.data);
}
} on GotrueError catch (error) {
Supabase.instance.log(error.message);
if (!_instance._initialSessionCompleter.isCompleted) {
_instance._initialSessionCompleter.completeError(error);
}
} catch (error) {
Supabase.instance.log(error.toString());
if (!_instance._initialSessionCompleter.isCompleted) {
_instance._initialSessionCompleter.completeError(error);
}
}
if (!_instance._initialSessionCompleter.isCompleted) {
_instance._initialSessionCompleter.complete(response.data);
}
}
}
Expand Down Expand Up @@ -171,13 +175,12 @@ class SupabaseAuth with WidgetsBindingObserver {
return false;
}

final response =
await Supabase.instance.client.auth.recoverSession(jsonStr);
if (response.error != null) {
try {
await Supabase.instance.client.auth.recoverSession(jsonStr);
return true;
} catch (error) {
SupabaseAuth.instance.localStorage.removePersistedSession();
return false;
} else {
return true;
}
}

Expand Down Expand Up @@ -274,9 +277,12 @@ class SupabaseAuth with WidgetsBindingObserver {

Future<void> _recoverSessionFromUrl(Uri uri) async {
// recover session from deeplink
final response = await Supabase.instance.client.auth.getSessionFromUrl(uri);
if (response.error != null) {
Supabase.instance.log(response.error!.message);
try {
await Supabase.instance.client.auth.getSessionFromUrl(uri);
} on GotrueError catch (error) {
Supabase.instance.log(error.message);
} catch (error) {
Supabase.instance.log(error.toString());
}
}

Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: supabase_flutter
description: Flutter integration for Supabase. This package makes it simple for developers to build secure and scalable products.
version: 0.3.3
version: 1.0.0-dev.1
homepage: 'https://supabase.io'
repository: 'https://github.com/supabase/supabase-flutter'

Expand All @@ -14,7 +14,7 @@ dependencies:
sdk: flutter
hive: ^2.2.1
hive_flutter: ^1.1.0
supabase: ^0.3.6
supabase: ^1.0.0-dev.1
url_launcher: ^6.1.2

dev_dependencies:
Expand Down
17 changes: 11 additions & 6 deletions test/widget_test_stubs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ class _MockWidgetState extends State<MockWidget> {
Widget build(BuildContext context) {
return isSignedIn
? TextButton(
onPressed: () {
Supabase.instance.client.auth.signOut();
onPressed: () async {
try {
await Supabase.instance.client.auth.signOut();
} catch (_) {}
},
child: const Text('Sign out'),
)
Expand All @@ -45,7 +47,7 @@ class MockLocalStorage extends LocalStorage {

/// 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}',
'{"currentSession":{"token_type": "","access_token":"","expires_in":3600,"refresh_token":"","user":{"app_metadata": {},"id":"","aud":"","created_at":"","role":"authenticated","updated_at":""}},"expiresAt":2147483647}',
persistSession: (_) async {},
removePersistedSession: () async {},
hasAccessToken: () async => true,
Expand All @@ -55,10 +57,13 @@ class MockLocalStorage extends LocalStorage {
// Register the mock handler for uni_links
void mockAppLink() {
const channel = MethodChannel('com.llfbandit.app_links/messages');
const anotherChannel = MethodChannel('com.llfbandit.app_links/events');

TestWidgetsFlutterBinding.ensureInitialized();

TestDefaultBinaryMessengerBinding.instance?.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (call) {
return null;
});
.setMockMethodCallHandler(channel, (call) => null);

TestDefaultBinaryMessengerBinding.instance?.defaultBinaryMessenger
.setMockMethodCallHandler(anotherChannel, (message) => null);
}

0 comments on commit b2a89a9

Please sign in to comment.