Skip to content

Commit 9c6105f

Browse files
authored
fix: ensure all params are trimmed [#236] (#251)
1 parent c132e72 commit 9c6105f

File tree

1 file changed

+12
-4
lines changed
  • packages/clerk_auth/lib/src/clerk_api

1 file changed

+12
-4
lines changed

packages/clerk_auth/lib/src/clerk_api/api.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,13 @@ class Api with Logging {
941941
.toList(growable: false);
942942
}
943943

944+
dynamic _ensureNotNullOrEmpty(dynamic param) {
945+
if (param case String param) {
946+
return param.trim().orNullIfEmpty;
947+
}
948+
return param;
949+
}
950+
944951
Future<http.Response> _fetch({
945952
required String path,
946953
HttpMethod method = HttpMethod.post,
@@ -950,9 +957,10 @@ class Api with Logging {
950957
bool withSession = false,
951958
}) async {
952959
final parsedParams = {
953-
for (final entry in (params ?? const {}).entries)
954-
if (entry.value != null) //
955-
entry.key: entry.value,
960+
if (params?.entries case final entries?) //
961+
for (final MapEntry(:key, :value) in entries) //
962+
if (_ensureNotNullOrEmpty(value) case final value?) //
963+
key: value,
956964
...?nullableParams,
957965
};
958966
final queryParams = _queryParams(
@@ -1021,7 +1029,7 @@ class Api with Logging {
10211029
HttpHeaders.contentTypeHeader: method.isGet
10221030
? 'application/json'
10231031
: 'application/x-www-form-urlencoded',
1024-
if (_tokenCache.clientToken.isNotEmpty) //
1032+
if (_tokenCache.hasClientToken) //
10251033
HttpHeaders.authorizationHeader: _tokenCache.clientToken,
10261034
_kClerkAPIVersion: ClerkConstants.clerkApiVersion,
10271035
_kXFlutterSDKVersion: ClerkConstants.flutterSdkVersion,

0 commit comments

Comments
 (0)