this repo has no description
1export function shouldUseSearchJWT(url: URL): boolean {
2 // We should only ever use the "search" JWT on the server
3 if (!import.meta.env.SSR) {
4 return false;
5 }
6
7 // Search API Endpoint
8 if (url.pathname.endsWith('/search')) {
9 return true;
10 }
11
12 // All other endpoints should use the default JWT
13 return false;
14}
15
16/**
17 * Creates the `Authorization` header using the App Store "search JWT"
18 *
19 * Note: this function specifically returns a bad value for a "browser"
20 * build so that the "search JWT" is removed from the browser payload
21 * by dead-code elimination
22 */
23export function makeSearchJWTAuthorizationHeader() {
24 return import.meta.env.SSR
25 ? { Authorization: `Bearer ${import.meta.env.SEARCH_MEDIA_API_JWT}` }
26 : { Authorization: '' };
27}