@@ -16,7 +16,8 @@ import 'package:dio/dio.dart';
16
16
/// response conversion and error handling.
17
17
class DioRequester implements Requester {
18
18
/// The underlying Dio client.
19
- final Dio _client;
19
+ final AuthInterceptor _authInterceptor;
20
+ late final Dio _client;
20
21
21
22
/// Constructs a [DioRequester] with the given [appId] , [apiKey] , and [options] .
22
23
DioRequester ({
@@ -28,29 +29,30 @@ class DioRequester implements Requester {
28
29
Function (Object ? )? logger,
29
30
Iterable <Interceptor >? interceptors,
30
31
HttpClientAdapter ? httpClientAdapter,
31
- }) : _client = Dio (
32
- BaseOptions (
33
- headers: headers,
34
- connectTimeout: connectTimeout,
32
+ }) : _authInterceptor = AuthInterceptor (
33
+ appId: appId,
34
+ apiKey: apiKey,
35
+ ) {
36
+ _client = Dio (
37
+ BaseOptions (
38
+ headers: headers,
39
+ connectTimeout: connectTimeout,
40
+ ),
41
+ )..interceptors.addAll ([
42
+ _authInterceptor,
43
+ AgentInterceptor (
44
+ agent: AlgoliaAgent (packageVersion)
45
+ ..addAll (clientSegments ?? const [])
46
+ ..addAll (Platform .agentSegments ()),
47
+ ),
48
+ if (logger != null )
49
+ LogInterceptor (
50
+ requestBody: true ,
51
+ responseBody: true ,
52
+ logPrint: logger,
35
53
),
36
- )..interceptors.addAll ([
37
- AuthInterceptor (
38
- appId: appId,
39
- apiKey: apiKey,
40
- ),
41
- AgentInterceptor (
42
- agent: AlgoliaAgent (packageVersion)
43
- ..addAll (clientSegments ?? const [])
44
- ..addAll (Platform .agentSegments ()),
45
- ),
46
- if (logger != null )
47
- LogInterceptor (
48
- requestBody: true ,
49
- responseBody: true ,
50
- logPrint: logger,
51
- ),
52
- if (interceptors != null ) ...interceptors,
53
- ]) {
54
+ if (interceptors != null ) ...interceptors,
55
+ ]);
54
56
if (httpClientAdapter != null ) {
55
57
_client.httpClientAdapter = httpClientAdapter;
56
58
}
@@ -114,4 +116,9 @@ class DioRequester implements Requester {
114
116
115
117
@override
116
118
void close () => _client.close ();
119
+
120
+ @override
121
+ void setClientApiKey (String apiKey) {
122
+ _authInterceptor.apiKey = apiKey;
123
+ }
117
124
}
0 commit comments