Skip to main content

login

The login feature lets merchants add Shop account authentication to their storefront.

The feature detects whether the current visitor is a known Shop user and can display a call-to-action button (for example, "Continue with Shop") or integrate inline with an existing email input field.


Create a login instance via the SDK:

const sdk = window.ShopSDK.initialize({
apiKey: 'YOUR_CLIENT_ID',
});

const login = await sdk.create('login', {
attributes: {
emailInputSelector: '#email',
},
onComplete(event) {
console.log('Authenticated:', event.email, event.signedIn);
},
});

document.querySelector('#login-mount').appendChild(login.element);

You can also eagerly preload the feature loader before calling create:

const sdk = window.ShopSDK.initialize({
apiKey: 'YOUR_CLIENT_ID',
features: { login: true },
});

Config accepted by sdk.create('login', config). Includes component attributes, appearance overrides, and event handlers.

The login feature provides Shop account authentication.

Anchor to appearance
appearance

Component-level appearance overrides.

Anchor to attributes
attributes

Component attributes.

Anchor to onBeforeAuthenticate
onBeforeAuthenticate
() => void | Promise<void>

Fired before authentication begins. Can be async.

Anchor to onComplete
onComplete
(event: ) => void

Fired when the login flow completes successfully.

Anchor to onConfirmSuccess
onConfirmSuccess
() => void

Fired after the user confirms a successful action.

Anchor to onError
onError
(event: ) => void

Fired when an error occurs during the flow.

Anchor to onGetEmailInput
onGetEmailInput
() => HTMLInputElement

Fired to retrieve the email input element (alternative to emailInputSelector).

Anchor to onLoad
onLoad
(event: ) => void

Fired when the component loads and user recognition completes.

Anchor to onReady
onReady
(event: ) => void

SDK-level ready handler (fires when the element's loader resolves).

Anchor to onRestart
onRestart
() => void

Fired when the user restarts the flow.

Runtime instance returned by sdk.create('login').

Exposes methods, attribute setters, and event subscriptions for the login flow.

Anchor to destroy
destroy
() => void
required

Tear down listeners and remove the element from the DOM if attached.

Anchor to element
element
HTMLElement
required

The underlying custom element. The consumer is responsible for inserting it into the DOM.

Anchor to notifyEmailFieldShown
notifyEmailFieldShown
() => void
required

Notify the component that the email field has been shown.

Anchor to onBeforeAuthenticate
onBeforeAuthenticate
(handler: () => void | Promise<void>) => void
required

Register an onBeforeAuthenticate handler.

Anchor to onComplete
onComplete
(handler: (event: ) => void) => void
required

Register an onComplete handler.

Anchor to onConfirmSuccess
onConfirmSuccess
(handler: () => void) => void
required

Register an onConfirmSuccess handler.

Anchor to onError
onError
(handler: (event: ) => void) => void
required

Register an onError handler.

Anchor to onLoad
onLoad
(handler: (event: ) => void) => void
required

Register an onLoad handler.

Anchor to onReady
onReady
(handler: (event: ) => void) => void
required

Register an onReady handler. Fires immediately if already ready.

Anchor to onRestart
onRestart
(handler: () => void) => void
required

Register an onRestart handler.

Anchor to setAttribute
setAttribute
(attrs: Partial<>) => void
required

Update one or more attributes on the underlying element.

Anchor to start
start
(email?: string) => void
required

Trigger the login flow, optionally with a pre-filled email.

Event payload dispatched when the login flow completes successfully.

Anchor to email
email
string
required

The email address captured from the user.

Anchor to signedIn
signedIn
boolean
required

Whether the user signed in during the flow (as opposed to only providing their email).

Anchor to consentedScopes
consentedScopes
string

A space-separated list of OAuth scopes the user consented to.

Anchor to customerAccessToken
customerAccessToken
string

A customer access token issued after authentication, if available.

Anchor to customerAccessTokenExpiresAt
customerAccessTokenExpiresAt
string

ISO 8601 timestamp of when the customer access token expires.

Anchor to emailVerified
emailVerified
boolean

Whether the user's email has been verified.

Anchor to shopConsentToken
shopConsentToken
string

A token that can be exchanged in the Shop Partners API to receive access for a user in the Shop Users API

Event payload dispatched when an error occurs during login.

string
required

A machine-readable error code.

Anchor to message
message
string
required

A human-readable error message.

Anchor to email
email
string

The email address associated with the error, if available.

Event payload dispatched when the login component finishes loading.

Anchor to userFound
userFound
boolean
required

Whether a recognized Shop user was detected for the current browser session.



Was this page helpful?