Skip to content

Commit c132e72

Browse files
fix: update tokens after reading/creating client [#244] (#250)
* fix: update tokens after reading/creating client [#244] * Update packages/clerk_auth/lib/src/clerk_api/api.dart --------- Co-authored-by: Simon Lightfoot <[email protected]>
1 parent 20ac2ba commit c132e72

File tree

1 file changed

+16
-9
lines changed
  • packages/clerk_auth/lib/src/clerk_api

1 file changed

+16
-9
lines changed

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ class Api with Logging {
114114
);
115115
if (resp.statusCode == HttpStatus.ok) {
116116
final body = json.decode(resp.body) as _JsonObject;
117-
return Client.fromJson(body[_kResponseKey]);
117+
final client = Client.fromJson(body[_kResponseKey]);
118+
_tokenCache.updateFrom(resp, client);
119+
return client;
118120
}
119121
return Client.empty;
120122
}
@@ -809,11 +811,10 @@ class Api with Logging {
809811
final resp = await _fetch(
810812
path: path,
811813
headers: _headers(),
812-
params: {
814+
nullableParams: {
813815
if (org case Organization org) //
814816
_kOrganizationId: org.externalId,
815817
},
816-
nullableKeys: [_kOrganizationId],
817818
);
818819
if (resp.statusCode == HttpStatus.ok) {
819820
final body = json.decode(resp.body) as _JsonObject;
@@ -945,14 +946,20 @@ class Api with Logging {
945946
HttpMethod method = HttpMethod.post,
946947
Map<String, String>? headers,
947948
_JsonObject? params,
949+
_JsonObject? nullableParams,
948950
bool withSession = false,
949-
List<String>? nullableKeys,
950951
}) async {
951-
final parsedParams = {...?params}..removeWhere(
952-
(key, value) => value == null && nullableKeys?.contains(key) != true,
953-
);
954-
final queryParams =
955-
_queryParams(method, withSession: withSession, params: parsedParams);
952+
final parsedParams = {
953+
for (final entry in (params ?? const {}).entries)
954+
if (entry.value != null) //
955+
entry.key: entry.value,
956+
...?nullableParams,
957+
};
958+
final queryParams = _queryParams(
959+
method,
960+
withSession: withSession,
961+
params: parsedParams,
962+
);
956963
final uri = _uri(path, params: queryParams);
957964

958965
final resp = await config.httpService.send(

0 commit comments

Comments
 (0)