Skip to content

Commit

Permalink
be explicit with naming
Browse files Browse the repository at this point in the history
  • Loading branch information
tshedor committed Aug 25, 2024
1 parent ae9b8a0 commit 9365fa2
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/offline_first/offline_first_with_supabase_repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MyRepository extends OfflineFirstWithSupabaseRepository {
static void configure({
required String supabaseUrl,
required String anonKey,
required String supabaseAnonKey,
}) {
// Convenience method `.clientQueue` makes creating the queue and client easy.
final (client, queue) = OfflineFirstWithSupabaseRepository.clientQueue(
Expand All @@ -50,7 +50,7 @@ class MyRepository extends OfflineFirstWithSupabaseRepository {
);

final provider = SupabaseProvider(
SupabaseClient(supabaseUrl, anonKey, httpClient: client),
SupabaseClient(supabaseUrl, supabaseAnonKey, httpClient: client),
modelDictionary: supabaseModelDictionary,
);

Expand Down
2 changes: 1 addition & 1 deletion example_supabase/lib/brick/repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Repository extends OfflineFirstWithRestRepository {
'${SUPABASE_PROJECT_URL}/rest/v1',
modelDictionary: restModelDictionary,
client: SupabaseBrickClient(
anonKey: SUPABASE_ANON_KEY,
supabaseAnonKey: SUPABASE_ANON_KEY,
),
),
sqliteProvider: SqliteProvider(
Expand Down
9 changes: 4 additions & 5 deletions example_supabase/lib/brick/supabase_brick_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import 'package:supabase_flutter/supabase_flutter.dart';
/// Supabase REST-API.
class SupabaseBrickClient extends http.BaseClient {
SupabaseBrickClient({
required this.anonKey,
required this.supabaseAnonKey,
http.Client? innerClient,
this.resourceName = 'dart.http',
}) : _innerClient = innerClient ?? http.Client();

/// The anon key of the supabase project.
///
/// This is sent in the request headers as the `apikey` field.
final String anonKey;
final String supabaseAnonKey;

/// Populates APM's "RESOURCE" column. Defaults to `dart.http`.
final String resourceName;
Expand All @@ -27,12 +27,11 @@ class SupabaseBrickClient extends http.BaseClient {
@override
Future<http.StreamedResponse> send(http.BaseRequest request) async {
// The access token is automatically refreshed by the supabase client
final accessToken =
Supabase.instance.client.auth.currentSession?.accessToken;
final accessToken = Supabase.instance.client.auth.currentSession?.accessToken;

request.headers.addAll({
if (accessToken != null) 'Authorization': 'Bearer $accessToken',
'apikey': anonKey,
'apikey': supabaseAnonKey,
'Content-Type': 'application/json; charset=utf-8',
// In order to use the upsert method for updates, the following header
// is needed for the REST API to work correctly.
Expand Down
5 changes: 2 additions & 3 deletions example_supabase/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:uuid/uuid.dart';
Future<void> main() async {
await Supabase.initialize(
url: SUPABASE_PROJECT_URL,
anonKey: SUPABASE_ANON_KEY,
supabaseAnonKey: SUPABASE_ANON_KEY,
);

Repository.configure();
Expand Down Expand Up @@ -71,8 +71,7 @@ class MyHomePage extends StatelessWidget {
? Center(child: Text('No customers found.'))
: ListView.builder(
itemCount: customers.length,
itemBuilder: (context, index) =>
CustomerListTile(customers[index]),
itemBuilder: (context, index) => CustomerListTile(customers[index]),
);
} else if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}'));
Expand Down
4 changes: 2 additions & 2 deletions packages/brick_offline_first_with_supabase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MyRepository extends OfflineFirstWithSupabaseRepository {
static void configure({
required String supabaseUrl,
required String anonKey,
required String supabaseAnonKey,
}) {
// Convenience method `.clientQueue` makes creating the queue and client easy.
final (client, queue) = OfflineFirstWithSupabaseRepository.clientQueue(
Expand All @@ -36,7 +36,7 @@ class MyRepository extends OfflineFirstWithSupabaseRepository {
);
final provider = SupabaseProvider(
SupabaseClient(supabaseUrl, anonKey, httpClient: client),
SupabaseClient(supabaseUrl, supabaseAnonKey, httpClient: client),
modelDictionary: supabaseModelDictionary,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MyRepository extends OfflineFirstWithSupabaseRepository {

static void configure({
required String supabaseUrl,
required String anonKey,
required String supabaseAnonKey,
}) {
final (client, queue) = OfflineFirstWithSupabaseRepository.clientQueue(
// For Flutter, use import 'package:sqflite/sqflite.dart' show databaseFactory;
Expand All @@ -39,7 +39,7 @@ class MyRepository extends OfflineFirstWithSupabaseRepository {
);

final provider = SupabaseProvider(
SupabaseClient(supabaseUrl, anonKey, httpClient: client),
SupabaseClient(supabaseUrl, supabaseAnonKey, httpClient: client),
modelDictionary: supabaseModelDictionary,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import 'package:sqflite_common/sqlite_api.dart' show DatabaseFactory;
/// databaseFactory: databaseFactory
/// );
/// final provider = SupabaseProvider(
/// SupabaseClient(supabaseUrl, anonKey, httpClient: client),
/// SupabaseClient(supabaseUrl, supabaseAnonKey, httpClient: client),
/// modelDictionary: supabaseModelDictionary,
/// );
///
Expand Down
4 changes: 2 additions & 2 deletions packages/brick_supabase/example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class User extends SupabaseModel {
}

class MyRepository extends SingleProviderRepository<SupabaseModel> {
MyRepository(String apiUrl, String anonKey)
MyRepository(String apiUrl, String supabaseAnonKey)
: super(
SupabaseProvider(
SupabaseClient(apiUrl, anonKey),
SupabaseClient(apiUrl, supabaseAnonKey),
modelDictionary: dictionary,
),
);
Expand Down

0 comments on commit 9365fa2

Please sign in to comment.