authenticateCustomer()
authenticateCustomer(
params):Promise<Success>
Authenticate a customer with a signed payload.
Parameters
| Parameter | Type | Description |
|---|---|---|
params | { shopifyCustomerId: number; signature: string; signatureTimestamp: number; } | Authentication parameters object. |
params.shopifyCustomerId | number | The Shopify customer ID (e.g., 123456789). |
params.signature | string | The SHA1 hash computed using shopifyCustomerId, signatureTimestamp, and your secretKey. |
params.signatureTimestamp | number | The Unix timestamp when the signature is created. |
Returns
Promise<Success>
Promise that resolves to a success result once the request is processed, or rejects with an error.
If logoutCustomer(), setToken() or another authenticateCustomer() call was made while this request was in flight,
the later call wins and this result is not applied. Check the outcome with getCurrentRole.
Remark
To authenticate customers, generate a signature on your server and call the authentication method.
signature = sha1("{shopifyCustomerId}{signatureTimestamp}{secretKey}")
shopifyCustomerId: The Shopify customer ID.signatureTimestamp: The Unix timestamp when the signature is created.secretKey: Your secret key from the Growave admin panel.
Security note: Always generate signatures on your server to keep your secretKey safe.
Example
Ensure the SDK is ready and the AuthenticationSdk module is initialized, then call authenticateCustomer.
function onSdkReady() {
window.gw.sdk.runIfModuleReady(
window.gw.sdk.common.constants.modules.AUTHENTICATION,
() => {
window.gw.sdk.authentication.methods.authenticateCustomer({
shopifyCustomerId,
signatureTimestamp,
signature,
});
}
);
}
if (window.gw && window.gw.sdk) {
onSdkReady();
} else {
document.addEventListener("gwSdkReady", onSdkReady);
}