-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathcreateAuth.ts
More file actions
30 lines (25 loc) · 810 Bytes
/
createAuth.ts
File metadata and controls
30 lines (25 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Auth, AuthMode, AuthModeType } from '.';
export function createAuth(authMode: AuthModeType, appId: string, apiKey: string): Auth {
const credentials = {
'x-algolia-api-key': apiKey,
'x-algolia-application-id': appId,
};
return {
headers(): Readonly<Record<string, string>> {
if (authMode === AuthMode.WithinHeaders) {
return credentials;
} else if (authMode === AuthMode.WithinBody) {
return {
'x-algolia-application-id': appId,
};
}
return {};
},
queryParameters(): Readonly<Record<string, string>> {
return authMode === AuthMode.WithinQueryParameters ? credentials : {};
},
data(): Readonly<Record<string, string>> {
return authMode === AuthMode.WithinBody ? { apiKey } : {};
},
};
}