Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ For integration testing, you may want to point to a local Supabase instance:
```dart
await Supabase.initialize(
url: 'http://localhost:54321',
anonKey: 'your-local-anon-key',
publishableKey: 'your-local-supabase-key',
);
```

Expand Down
2 changes: 1 addition & 1 deletion packages/functions_client/lib/src/functions_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class FunctionsClient {
/// final fetchClient = FetchClient(mode: RequestMode.cors);
/// await Supabase.initialize(
/// url: supabaseUrl,
/// anonKey: supabaseKey,
/// publishableKey: supabaseKey,
/// httpClient: fetchClient,
/// );
/// ```
Expand Down
8 changes: 4 additions & 4 deletions packages/gotrue/lib/src/gotrue_admin_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GoTrueAdminApi {

/// Creates a new user.
///
/// This function should only be called on a server. Never expose your `service_role` key on the client.
/// This function should only be called on a server. Never expose your `secret` key on the client.
///
/// Requires either an email or phone
Future<UserResponse> createUser(AdminUserAttributes attributes) async {
Expand All @@ -75,11 +75,11 @@ class GoTrueAdminApi {
return UserResponse.fromJson(response);
}

/// Delete a user. Requires a `service_role` key.
/// Delete a user. Requires a `secret` key.
///
/// [id] is the user id of the user you want to remove.
///
/// This function should only be called on a server. Never expose your `service_role` key on the client.
/// This function should only be called on a server. Never expose your `secret` key on the client.
Future<void> deleteUser(String id) async {
validateUuid(id);
final options = GotrueRequestOptions(headers: _headers);
Expand All @@ -92,7 +92,7 @@ class GoTrueAdminApi {

/// Get a list of users.
///
/// This function should only be called on a server. Never expose your `service_role` key on the client.
/// This function should only be called on a server. Never expose your `secret` key on the client.
///
/// The result is paginated. Use the [page] and [perPage] parameters to paginate the result.
Future<List<User>> listUsers({int? page, int? perPage}) async {
Expand Down
12 changes: 6 additions & 6 deletions packages/gotrue/lib/src/gotrue_admin_oauth_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class GoTrueAdminOAuthApi {
/// Lists all OAuth clients with optional pagination.
/// Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
///
/// This function should only be called on a server. Never expose your `service_role` key in the browser.
/// This function should only be called on a server. Never expose your `secret` key in the browser.
Future<OAuthClientListResponse> listClients({
int? page,
int? perPage,
Expand All @@ -88,7 +88,7 @@ class GoTrueAdminOAuthApi {
/// Creates a new OAuth client.
/// Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
///
/// This function should only be called on a server. Never expose your `service_role` key in the browser.
/// This function should only be called on a server. Never expose your `secret` key in the browser.
Future<OAuthClientResponse> createClient(
CreateOAuthClientParams params,
) async {
Expand All @@ -107,7 +107,7 @@ class GoTrueAdminOAuthApi {
/// Gets details of a specific OAuth client.
/// Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
///
/// This function should only be called on a server. Never expose your `service_role` key in the browser.
/// This function should only be called on a server. Never expose your `secret` key in the browser.
Future<OAuthClientResponse> getClient(String clientId) async {
validateUuid(clientId);

Expand All @@ -125,7 +125,7 @@ class GoTrueAdminOAuthApi {
/// Updates an existing OAuth client.
/// Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
///
/// This function should only be called on a server. Never expose your `service_role` key in the browser.
/// This function should only be called on a server. Never expose your `secret` key in the browser.
Future<OAuthClientResponse> updateClient(
String clientId,
UpdateOAuthClientParams params,
Expand All @@ -147,7 +147,7 @@ class GoTrueAdminOAuthApi {
/// Deletes an OAuth client.
/// Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
///
/// This function should only be called on a server. Never expose your `service_role` key in the browser.
/// This function should only be called on a server. Never expose your `secret` key in the browser.
Future<OAuthClientResponse> deleteClient(String clientId) async {
validateUuid(clientId);

Expand All @@ -165,7 +165,7 @@ class GoTrueAdminOAuthApi {
/// Regenerates the secret for an OAuth client.
/// Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
///
/// This function should only be called on a server. Never expose your `service_role` key in the browser.
/// This function should only be called on a server. Never expose your `secret` key in the browser.
Future<OAuthClientResponse> regenerateClientSecret(String clientId) async {
validateUuid(clientId);

Expand Down
18 changes: 7 additions & 11 deletions packages/supabase/example/web/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:web/web.dart' as web;

void main() {
const supabaseUrl = 'YOUR_SUPABASE_URL';
const supabaseKey = 'YOUR_ANON_KEY';
const supabaseKey = 'YOUR_SUPABASE_KEY';
final supabase = SupabaseClient(supabaseUrl, supabaseKey);

final element = web.document.querySelector('#output') as web.HTMLDivElement;
Expand All @@ -16,10 +16,8 @@ void main() {

void exampleUsage(SupabaseClient supabase) async {
// query data
final data = await supabase
.from('countries')
.select()
.order('name', ascending: true);
final data =
await supabase.from('countries').select().order('name', ascending: true);
print(data);

// insert data
Expand Down Expand Up @@ -76,15 +74,13 @@ void exampleUsage(SupabaseClient supabase) async {
print('upload response : $storageResponse');

// Get download url
final urlResponse = await supabase.storage
.from('public')
.createSignedUrl('example.txt', 60);
final urlResponse =
await supabase.storage.from('public').createSignedUrl('example.txt', 60);
print('download url : $urlResponse');

// Download text file
final fileResponse = await supabase.storage
.from('public')
.download('example.txt');
final fileResponse =
await supabase.storage.from('public').download('example.txt');
print('downloaded file : ${String.fromCharCodes(fileResponse)}');

// Delete file
Expand Down
2 changes: 2 additions & 0 deletions packages/supabase/lib/src/supabase_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import 'counter.dart';
/// Creates a Supabase client to interact with your Supabase instance.
///
/// [supabaseUrl] and [supabaseKey] can be found on your Supabase dashboard.
/// Pass the `publishable` (anon) key for client-side usage or the `secret`
/// key for trusted server-side environments.
///
/// You can access none public schema by passing different [schema].
///
Expand Down
2 changes: 1 addition & 1 deletion packages/supabase_flutter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main() async {

await Supabase.initialize(
url: SUPABASE_URL,
anonKey: SUPABASE_ANON_KEY,
publishableKey: SUPABASE_KEY,
);

runApp(MyApp());
Expand Down
3 changes: 2 additions & 1 deletion packages/supabase_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import 'package:flutter/material.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

Future<void> main() async {
await Supabase.initialize(url: 'SUPABASE_URL', anonKey: 'SUPABASE_ANON_KEY');
await Supabase.initialize(
url: 'SUPABASE_URL', publishableKey: 'SUPABASE_PUBLISHABLE_KEY');
runApp(const MyApp());
}

Expand Down
22 changes: 17 additions & 5 deletions packages/supabase_flutter/lib/src/supabase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ class Supabase {
/// This must be called only once. If called more than once, an
/// [AssertionError] is thrown
///
/// [url] and [anonKey] can be found on your Supabase dashboard.
/// [url] and [publishableKey] can be found on your Supabase dashboard.
/// Use the `publishable` (anon) key here — never the secret key in a
/// Flutter app.
///
/// You can access none public schema by passing different [schema].
///
Expand All @@ -76,7 +78,11 @@ class Supabase {
/// If [debug] is set to `true`, debug logs will be printed in debug console. Default is `kDebugMode`.
static Future<Supabase> initialize({
required String url,
required String anonKey,
String? publishableKey,
@Deprecated(
'Use publishableKey instead. anonKey will be removed in a future major version.',
)
String? anonKey,
Map<String, String>? headers,
Client? httpClient,
RealtimeClientOptions realtimeClientOptions = const RealtimeClientOptions(),
Expand All @@ -86,6 +92,12 @@ class Supabase {
Future<String?> Function()? accessToken,
bool? debug,
}) async {
assert(
publishableKey != null || anonKey != null,
'Either publishableKey or anonKey must be provided.',
);
final effectiveKey = publishableKey ?? anonKey!;

if (_instance._isInitialized) {
_log.info('Supabase is already initialized. Skipping reinitialization.');
return _instance;
Expand Down Expand Up @@ -120,7 +132,7 @@ class Supabase {
}
_instance._init(
url,
anonKey,
effectiveKey,
httpClient: httpClient,
customHeaders: headers,
realtimeClientOptions: realtimeClientOptions,
Expand Down Expand Up @@ -193,7 +205,7 @@ class Supabase {

void _init(
String supabaseUrl,
String supabaseAnonKey, {
String supabaseKey, {
Client? httpClient,
Map<String, String>? customHeaders,
required RealtimeClientOptions realtimeClientOptions,
Expand All @@ -208,7 +220,7 @@ class Supabase {
};
client = SupabaseClient(
supabaseUrl,
supabaseAnonKey,
supabaseKey,
httpClient: httpClient,
headers: headers,
realtimeClientOptions: realtimeClientOptions,
Expand Down
8 changes: 4 additions & 4 deletions packages/supabase_flutter/test/auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void main() {

await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
debug: false,
authOptions: FlutterAuthClientOptions(
localStorage: mockStorage,
Expand All @@ -67,7 +67,7 @@ void main() {
() async {
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
debug: false,
authOptions: FlutterAuthClientOptions(
localStorage: MockEmptyLocalStorage(),
Expand All @@ -94,7 +94,7 @@ void main() {

await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
debug: false,
authOptions: FlutterAuthClientOptions(
localStorage: corruptedStorage,
Expand All @@ -112,7 +112,7 @@ void main() {

await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
debug: false,
authOptions: FlutterAuthClientOptions(
localStorage: emptyStorage,
Expand Down
2 changes: 1 addition & 1 deletion packages/supabase_flutter/test/deep_link_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void main() {
);
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
debug: false,
httpClient: pkceHttpClient,
authOptions: FlutterAuthClientOptions(
Expand Down
20 changes: 10 additions & 10 deletions packages/supabase_flutter/test/initialization_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void main() {
test('initialize successfully with default options', () async {
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
);

expect(Supabase.instance, isNotNull);
Expand All @@ -41,7 +41,7 @@ void main() {
final localStorage = MockLocalStorage();
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
authOptions: FlutterAuthClientOptions(
localStorage: localStorage,
),
Expand All @@ -54,7 +54,7 @@ void main() {
test('handles initialization with expired session in storage', () async {
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
debug: true,
authOptions: FlutterAuthClientOptions(
localStorage: MockExpiredStorage(),
Expand All @@ -71,7 +71,7 @@ void main() {
test('initialize successfully with PKCE auth flow', () async {
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
authOptions: const FlutterAuthClientOptions(
authFlowType: AuthFlowType.pkce,
),
Expand All @@ -87,7 +87,7 @@ void main() {
final httpClient = PkceHttpClient();
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
httpClient: httpClient,
);

Expand All @@ -98,7 +98,7 @@ void main() {
test('initialize successfully with custom access token', () async {
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
accessToken: () async => 'custom-access-token',
);

Expand All @@ -118,7 +118,7 @@ void main() {
// First initialization
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
);

expect(Supabase.instance, isNotNull);
Expand All @@ -132,7 +132,7 @@ void main() {
// Re-initialize should work without errors
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
);

expect(Supabase.instance, isNotNull);
Expand All @@ -141,7 +141,7 @@ void main() {
test('handles multiple initializations correctly', () async {
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
debug: false,
authOptions: FlutterAuthClientOptions(
localStorage: MockLocalStorage(),
Expand All @@ -157,7 +157,7 @@ void main() {

await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
debug: true,
authOptions: FlutterAuthClientOptions(
localStorage: MockEmptyLocalStorage(),
Expand Down
2 changes: 1 addition & 1 deletion packages/supabase_flutter/test/lifecycle_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void main() {
readyCompleters = [];
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
publishableKey: supabaseKey,
debug: false,
authOptions: FlutterAuthClientOptions(
localStorage: MockEmptyLocalStorage(),
Expand Down
Loading
Loading