SubblySubbly
Log inGet started
  • Get started
  • Developer resources
Subbly.js SDK reference
Docs
Information
    CookiesAmounts and datesCurrencyExpand parametersErrors
Setup
    Start the SDKSet the currencySet the languageVersionConfiguration
Addresses
    List the addressesAdd an addressDelete an address
Authentication
    Authentication stateCheck the authenticationLog in with a passwordRegister a customerCheck if an email is registeredSend a one-time passwordLog in with a one-time passwordLog in with single sign-onLog outGet the access token
Bundles
    List the bundlesLoad a bundleLoad the bundle itemsLoad the bundle groupsQuote a bundle
Cart
    Create a cartLoad a cartUpdate the cartAdd an itemUpdate an itemRemove an itemGet the start datesGet the gifting datesGet the shipping methodsGet the pick-up pointsAttach the customer
Checkout
    Purchase the cart
Countries
    List the countries
Customers
    Get the customer profileUpdate the customerGet the referral link
Funnels
    Get a pre-purchase offerAccept a pre-purchase offerSkip a pre-purchase offerReset the pre-purchase offersGet a mid-purchase offerAccept a mid-purchase offerSkip a mid-purchase offerGet a post-purchase offerAccept a post-purchase offerSkip a post-purchase offer
Leads
    Capture a lead
Metafields
    List the metafields
Payment intents
    Get a payment intentConfirm a payment intent
Pick-up info
    List the pick-up infosAdd a pick-up infoDelete a pick-up info
Products
    List the productsLoad a productLoad a variantLoad a plan
Shop
    Load the shop
Stock notifications
    Get a back-in-stock alert
Subscriptions
    List the subscriptionsLoad a subscriptionUpdate a subscriptionUpdate the survey preferencesUpdate the bundleLoad a subscription itemUpdate a subscription itemUpdate an item bundleUpdate the item survey preferences
Surveys
    Load a survey
Wallet
    List the payment methodsStart a payment setupAdd a payment methodStart a 3-D Secure setup

Authentication

Sign a customer in, register a new one, and hold the access token.

A successful sign-in writes the access token to the subbly_access_token cookie, sets the Authorization header on the shared HTTP client, and flips subbly.auth.isAuthenticated to true. The cookie lasts 365 days and is set on path=/. It is a plain cookie: the SDK sets no Secure, HttpOnly or SameSite attribute, so treat it as readable by any script on the host.

subbly.auth.isAuthenticated

A boolean property, not a method. It is true after a successful checkAuthenticated, login, register, otpLogin or social, and false after logout. Nothing watches it, so read it after an authentication call rather than expecting it to update on its own.

Returnsboolean

true when the SDK holds a token it has checked.

Branch on the authentication state
if (subbly.auth.isAuthenticated) { const customer = await subbly.customers.me() }

subbly.auth.checkAuthenticated(token?)

Verifies that the SDK can call the methods that need a signed-in customer. Subbly.init calls it for you at start-up.

The check costs one request: it calls subbly.customers.me() behind the scenes. When it passes, the SDK sets the Authorization header and, if you passed a token, writes it to the cookie. When it fails, the SDK clears the header and the cookie and logs the error to the console.

Method parameters

tokenoptionalstring

An access token to check. It beats the token in the cookie. Leave it out to check the token already stored.

ReturnsPromise<boolean>

true when the customer is signed in. It resolves with false rather than rejecting when there is no token or the token is rejected.

Check the stored token
const signedIn = await subbly.auth.checkAuthenticated()
Check a token you hold
const signedIn = await subbly.auth.checkAuthenticated('eyJh...eyJ9')

subbly.auth.login(payload)

Signs the customer in with an email and a password.

Method parameters

payloadRequiredAuthResourceLoginPayload

The credentials.

ReturnsPromise<AuthResourceLoginResponse>

The new token. The SDK stores it for you.

Log in
await subbly.auth.login({ email: 'ada@example.com', password: 'correct horse battery staple', })

subbly.auth.register(payload)

Creates an account and signs the new customer in. It stores the token exactly as login does.

Method parameters

payloadRequiredAuthResourceRegisterPayload

The new customer.

ReturnsPromise<AuthResourceLoginResponse>

The new token, in the same shape login returns.

Register a customer
await subbly.auth.register({ email: 'ada@example.com', firstName: 'Ada', lastName: 'Lovelace', })

subbly.auth.registered(payload)

Reports whether an email already has a Subbly account. Use it to send the customer to the sign-in form instead of the sign-up form.

Method parameters

payloadRequiredAuthResourceRegisteredPayload

The email to look up.

emailRequiredstring

Email address to check.

ReturnsPromise<AuthResourceRegisteredResponse>

The answer.

registeredboolean

true when an account already exists for the email.

Check an email
const { registered } = await subbly.auth.registered({ email: 'ada@example.com', })

subbly.auth.otp(payload)

Emails a one-time password to the address you give. Pass the code the customer types back to subbly.auth.otpLogin.

Method parameters

payloadRequiredAuthResourceOtpPayload

Where to send the code.

emailRequiredstring

Email address to send the one-time password to.

ReturnsPromise<void>

Nothing. The response body is empty.

Send a one-time password
await subbly.auth.otp({ email: 'ada@example.com' })

subbly.auth.otpLogin(payload)

Signs the customer in with the one-time password subbly.auth.otp emailed. It stores the token exactly as login does.

Method parameters

payloadRequiredAuthResourceOtpLoginPayload

The email and the code.

ReturnsPromise<AuthResourceLoginResponse>

The new token, in the same shape login returns.

Log in with a one-time password
await subbly.auth.otpLogin({ email: 'ada@example.com', token: '123456', })

subbly.auth.social(payload)

Signs the customer in with a Google or Facebook token. The provider must be switched on for the shop; look for a google_login or facebook_login entry in subbly.shop.apps. It stores the token exactly as login does.

Method parameters

payloadRequiredAuthResourceSocialPayload

The token from the provider.

ReturnsPromise<AuthResourceLoginResponse>

The new token, in the same shape login returns.

Log in with Google
await subbly.auth.social({ token: googleIdToken, provider: 'google', })

subbly.auth.logout()

Clears the authentication state in the browser: it sets isAuthenticated to false, drops the Authorization header, and empties the subbly_access_token cookie.

It sends no request, so the token itself stays valid until it expires. Do not rely on logout to lock anything down on the server.

Returnsvoid

Nothing. This method is not a promise.

Log out
subbly.auth.logout()

subbly.auth.getAccessToken()

Reads the access token out of the subbly_access_token cookie. It is synchronous and makes no request. Use it to hand the token to your own backend.

Returnsstring | null

The stored token. null when there is no cookie, and an empty string after subbly.auth.logout(). The TypeScript type says string | undefined; the SDK never returns undefined.

Read the access token
const token = subbly.auth.getAccessToken()
Last modified on September 15, 2026
Javascript
Javascript
Javascript
emailRequiredstring

Email address of the customer.

passwordRequiredstring

Password of the customer.

accessTokenstring

The customer access token. The SDK stores it in the subbly_access_token cookie and sends it with every later request, so you rarely need to read it.

expiresInnumber

How long the token lasts, in seconds.

Javascript
emailRequiredstring

Email address. It must not already have a Subbly account.

firstNameRequiredstring

Given name.

lastNameRequiredstring

Family name.

passwordoptionalstring

Password. Leave it out and Subbly generates one and emails it to the customer.

accessTokenstring

The customer access token. The SDK stores it in the subbly_access_token cookie and sends it with every later request, so you rarely need to read it.

expiresInnumber

How long the token lasts, in seconds.

Javascript
Javascript
Javascript
emailRequiredstring

The address the code went to.

tokenRequiredstring

The one-time password the customer typed, such as 123456.

accessTokenstring

The customer access token. The SDK stores it in the subbly_access_token cookie and sends it with every later request, so you rarely need to read it.

expiresInnumber

How long the token lasts, in seconds.

Javascript
tokenRequiredstring

The ID token the provider's own SDK gave you.

providerRequiredstring

Which service issued the token: google or facebook.

accessTokenstring

The customer access token. The SDK stores it in the subbly_access_token cookie and sends it with every later request, so you rarely need to read it.

expiresInnumber

How long the token lasts, in seconds.

Javascript
Javascript
Javascript