configureAuth method

Future<void> configureAuth({
  1. required String projectRef,
  2. required String accessToken,
  3. required Map<String, dynamic> authConfig,
})

Configures the project's auth settings via the Management API.

Maps to PATCH /v1/projects/{ref}/config/auth. The body is an opaque JSON object whose keys match the Management API's auth config fields (e.g. SITE_URL, URI_ALLOW_LIST, MAILER_SUBJECTS_CONFIRMATION). Using an opaque map avoids coupling this method's signature to Supabase's evolving field names.

Called during AccessTokenDialogMode.fullBootstrap to set the site URL (so confirmation emails link to the app, not localhost:3000) and customize mailer subjects. Idempotent — PATCHing the same values twice is a no-op.

Implementation

Future<void> configureAuth({
  required String projectRef,
  required String accessToken,
  required Map<String, dynamic> authConfig,
}) async {
  if (authConfig.isEmpty) return;
  final url = '$_baseUrl/v1/projects/$projectRef/config/auth';

  final Response<dynamic> response;
  try {
    response = await _dio.patch<dynamic>(
      url,
      data: authConfig,
      options: Options(
        headers: {
          ..._authHeaders(accessToken),
          'Content-Type': 'application/json',
        },
        sendTimeout: _timeout,
        receiveTimeout: _timeout,
        validateStatus: (_) => true,
      ),
    );
  } on DioException catch (e) {
    throw ProvisioningException(_dioMessage(e, 'configuring authentication'));
  }

  final status = response.statusCode ?? 0;
  if (status >= 200 && status < 300) {
    dev.log(
      'Auth configured on project $projectRef '
      '(${authConfig.length} settings).',
      name: 'SupabaseProvisioner',
    );
    return;
  }
  throw ProvisioningException(_mapStatus(status, projectRef, response.data));
}