File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
clients/algoliasearch-client-javascript/packages/client-common/src
templates/javascript/clients Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ export function createAuth(
7
7
) : {
8
8
readonly headers : ( ) => Headers ;
9
9
readonly queryParameters : ( ) => QueryParameters ;
10
+ readonly setApiKey : ( newApiKey : string ) => void ;
10
11
} {
11
12
const credentials = {
12
13
'x-algolia-api-key' : apiKey ,
@@ -21,5 +22,9 @@ export function createAuth(
21
22
queryParameters ( ) : QueryParameters {
22
23
return authMode === 'WithinQueryParameters' ? credentials : { } ;
23
24
} ,
25
+
26
+ setApiKey ( newApiKey : string ) : void {
27
+ credentials [ 'x-algolia-api-key' ] = newApiKey ;
28
+ } ,
24
29
} ;
25
30
}
Original file line number Diff line number Diff line change @@ -75,6 +75,15 @@ export function create{{#lambda.titlecase}}{{apiName}}{{/lambda.titlecase}}({
75
75
transporter.algoliaAgent.add({ segment, version } );
76
76
},
77
77
78
+ /**
79
+ * Helper method to switch the API key used to authenticate the requests.
80
+ *
81
+ * @param apiKey - The new API Key to use.
82
+ */
83
+ setApiKey(apiKey: string): void {
84
+ auth.setApiKey(apiKey);
85
+ } ,
86
+
78
87
{ {#isSearchClient} }
79
88
{ {> client/api/helpers} }
80
89
{ {/isSearchClient} }
You can’t perform that action at this time.
0 commit comments