Skip to content

Commit 9711b82

Browse files
committed
Introduce new public auth mode for single shop tenant
1 parent 0bfc4f6 commit 9711b82

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

packages/api-client-core/src/ClientOptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ export interface AuthenticationModeOptions {
103103
getSessionId?: () => Promise<string | undefined>;
104104
};
105105

106+
publicShopTenant?: {
107+
shopId: string;
108+
};
109+
106110
// @private Use a passed custom function for managing authentication. For some fancy integrations that the API client supports, like embedded Shopify apps, we use platform native features to authenticate with the Gadget backend.
107111
custom?: {
108112
processFetch(input: RequestInfo | URL, init: RequestInit): Promise<void>;

packages/api-client-core/src/GadgetConnection.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export enum AuthenticationMode {
7474
InternalAuthToken = "internal-auth-token",
7575
Anonymous = "anonymous",
7676
Custom = "custom",
77+
PublicShopTenant = "public-shop-tenant",
7778
}
7879

7980
const objectForGlobals = typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : undefined;
@@ -173,6 +174,8 @@ export class GadgetConnection {
173174
this.authenticationMode = AuthenticationMode.InternalAuthToken;
174175
} else if (options.apiKey) {
175176
this.authenticationMode = AuthenticationMode.APIKey;
177+
} else if (options.publicShopTenant) {
178+
this.authenticationMode = AuthenticationMode.PublicShopTenant;
176179
} else if (options.custom) {
177180
this.authenticationMode = AuthenticationMode.Custom;
178181
}
@@ -552,6 +555,11 @@ export class GadgetConnection {
552555
if (val) {
553556
headers.authorization = `Session ${val}`;
554557
}
558+
} else if (this.authenticationMode === AuthenticationMode.PublicShopTenant) {
559+
const shopId = this.options.authenticationMode?.publicShopTenant?.shopId;
560+
if (shopId) {
561+
headers["x-gadget-public-shop-tenant"] = shopId;
562+
}
555563
}
556564

557565
headers["x-gadget-environment"] = this.environment;

0 commit comments

Comments
 (0)