diff --git a/packages/clerk_auth/lib/clerk_auth.dart b/packages/clerk_auth/lib/clerk_auth.dart index a009423..4b88f18 100644 --- a/packages/clerk_auth/lib/clerk_auth.dart +++ b/packages/clerk_auth/lib/clerk_auth.dart @@ -1,6 +1,7 @@ /// Package that will allow you to authenticate and use Clerk from Dart code. library clerk_auth; +export 'clerk_constants.dart'; export 'src/clerk_api/api.dart'; export 'src/clerk_auth/auth.dart'; export 'src/clerk_auth/persistor.dart'; diff --git a/packages/clerk_auth/lib/clerk_constants.dart b/packages/clerk_auth/lib/clerk_constants.dart new file mode 100644 index 0000000..8a1d342 --- /dev/null +++ b/packages/clerk_auth/lib/clerk_constants.dart @@ -0,0 +1,8 @@ +/// constant values +sealed class ClerkConstants { + /// value for the `clerk-api-version` header in API requests + static const clerkApiVersion = '2024-10-01'; + + /// value for the `x-flutter-sdk-version` header in API requests + static const flutterSdkVersion = '0.0.4-dev'; +} diff --git a/packages/clerk_auth/lib/src/clerk_api/api.dart b/packages/clerk_auth/lib/src/clerk_api/api.dart index 33a9c5f..e609533 100644 --- a/packages/clerk_auth/lib/src/clerk_api/api.dart +++ b/packages/clerk_auth/lib/src/clerk_api/api.dart @@ -66,6 +66,9 @@ class Api with Logging { static const _kErrorsKey = 'errors'; static const _kClientKey = 'client'; static const _kResponseKey = 'response'; + static const _kClerkAPIVersion = 'clerk-api-version'; + static const _kXFlutterSDKVersion = 'x-flutter-sdk-version'; + static const _kXMobile = 'x-mobile'; static const _defaultPollDelay = Duration(seconds: 55); @@ -674,6 +677,9 @@ class Api with Logging { : 'application/x-www-form-urlencoded', if (_tokenCache.clientToken.isNotEmpty) // HttpHeaders.authorizationHeader: _tokenCache.clientToken, + _kClerkAPIVersion: ClerkConstants.clerkApiVersion, + _kXFlutterSDKVersion: ClerkConstants.flutterSdkVersion, + _kXMobile: '1', ...?headers, }; } diff --git a/packages/clerk_auth/lib/src/clerk_auth/http_client.dart b/packages/clerk_auth/lib/src/clerk_auth/http_client.dart index bedca74..0bb55c2 100644 --- a/packages/clerk_auth/lib/src/clerk_auth/http_client.dart +++ b/packages/clerk_auth/lib/src/clerk_auth/http_client.dart @@ -74,9 +74,13 @@ class DefaultHttpClient implements HttpClient { }) async { final request = Request(method.toString(), uri); - if (headers != null) request.headers.addAll(headers); + if (headers case Map headers) { + request.headers.addAll(headers); + } - if (params != null) request.bodyFields = params.toStringMap(); + if (params case Map params) { + request.bodyFields = params.toStringMap(); + } final streamedResponse = await request.send(); return Response.fromStream(streamedResponse);