Skip to content
This repository has been archived by the owner on May 13, 2023. It is now read-only.

Commit

Permalink
feat: add async storage as parameter to support pkce flow (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
dshukertjr committed May 3, 2023
1 parent 729a80e commit 001e31d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## [1.7.0]
- feat: add async storage as parameter to support pkce flow [#190](https://github.com/supabase/supabase-dart/pull/190)
- fix: use onAuthStateChangeSync to set auth headers [#193](https://github.com/supabase/supabase-dart/pull/193)

## [1.6.4]
- fix: race condition for passing auth headers for rest client [#192](https://github.com/supabase/supabase-dart/pull/192)

Expand Down
48 changes: 31 additions & 17 deletions lib/src/supabase_client.dart
Expand Up @@ -11,6 +11,28 @@ import 'package:supabase/src/realtime_client_options.dart';
import 'package:supabase/src/supabase_query_builder.dart';
import 'package:yet_another_json_isolate/yet_another_json_isolate.dart';

/// {@template supabase_client}
/// Creates a Supabase client to interact with your Supabase instance.
///
/// [supabaseUrl] and [supabaseKey] can be found on your Supabase dashboard.
///
/// You can access none public schema by passing different [schema].
///
/// Default headers can be overridden by specifying [headers].
///
/// Custom http client can be used by passing [httpClient] parameter.
///
/// [storageRetryAttempts] specifies how many retry attempts there should be to
/// upload a file to Supabase storage when failed due to network interruption.
///
/// [realtimeClientOptions] specifies different options you can pass to `RealtimeClient`.
///
/// Pass an instance of `YAJsonIsolate` to [isolate] to use your own persisted
/// isolate instance. A new instance will be created if [isolate] is omitted.
///
/// Pass an instance of [gotrueAsyncStorage] and set the [authFlowType] to
/// `AuthFlowType.pkce`in order to perform auth actions with pkce flow.
/// {@endtemplate}
class SupabaseClient {
final String supabaseUrl;
final String supabaseKey;
Expand Down Expand Up @@ -42,23 +64,7 @@ class SupabaseClient {
/// Number of retries storage client should do on file failed file uploads.
final int _storageRetryAttempts;

/// Creates a Supabase client to interact with your Supabase instance.
///
/// [supabaseUrl] and [supabaseKey] can be found on your Supabase dashboard.
///
/// You can access none public schema by passing different [schema].
///
/// Default headers can be overridden by specifying [headers].
///
/// Custom http client can be used by passing [httpClient] parameter.
///
/// [storageRetryAttempts] specifies how many retry attempts there should be to
/// upload a file to Supabase storage when failed due to network interruption.
///
/// [realtimeClientOptions] specifies different options you can pass to `RealtimeClient`.
///
/// Pass an instance of `YAJsonIsolate` to [isolate] to use your own persisted
/// isolate instance. A new instance will be created if [isolate] is omitted.
/// {@macro supabase_client}
SupabaseClient(
this.supabaseUrl,
this.supabaseKey, {
Expand All @@ -69,6 +75,8 @@ class SupabaseClient {
int storageRetryAttempts = 0,
RealtimeClientOptions realtimeClientOptions = const RealtimeClientOptions(),
YAJsonIsolate? isolate,
GotrueAsyncStorage? gotrueAsyncStorage,
AuthFlowType authFlowType = AuthFlowType.implicit,
}) : restUrl = '$supabaseUrl/rest/v1',
realtimeUrl = '$supabaseUrl/realtime/v1'.replaceAll('http', 'ws'),
authUrl = '$supabaseUrl/auth/v1',
Expand All @@ -85,6 +93,8 @@ class SupabaseClient {
auth = _initSupabaseAuthClient(
autoRefreshToken: autoRefreshToken,
headers: headers,
gotrueAsyncStorage: gotrueAsyncStorage,
authFlowType: authFlowType,
);
rest = _initRestClient();
functions = _initFunctionsClient();
Expand Down Expand Up @@ -157,6 +167,8 @@ class SupabaseClient {
GoTrueClient _initSupabaseAuthClient({
bool? autoRefreshToken,
required Map<String, String> headers,
required GotrueAsyncStorage? gotrueAsyncStorage,
required AuthFlowType authFlowType,
}) {
final authHeaders = {...headers};
authHeaders['apikey'] = supabaseKey;
Expand All @@ -167,6 +179,8 @@ class SupabaseClient {
headers: authHeaders,
autoRefreshToken: autoRefreshToken,
httpClient: _httpClient,
asyncStorage: gotrueAsyncStorage,
flowType: authFlowType,
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.dart
@@ -1 +1 @@
const version = '1.6.4';
const version = '1.7.0';
4 changes: 2 additions & 2 deletions pubspec.yaml
@@ -1,6 +1,6 @@
name: supabase
description: A dart client for Supabase. This client makes it simple for developers to build secure and scalable products.
version: 1.6.4
version: 1.7.0
homepage: 'https://supabase.io'
repository: 'https://github.com/supabase/supabase-dart'

Expand All @@ -9,7 +9,7 @@ environment:

dependencies:
functions_client: ^1.1.0
gotrue: ^1.5.1
gotrue: ^1.7.0
http: ^0.13.4
postgrest: ^1.2.3
realtime_client: ^1.0.2
Expand Down

0 comments on commit 001e31d

Please sign in to comment.