Going Further

Hooks

Hooks for the Nuxt Shopify module

The module provides several hooks that can be used to customize its behavior. These hooks are available in the hooks property of the module configuration and within your Nuxt and Nitro app.

Using client runtime hooks

You can use the client runtime hooks in a Nuxt plugin or Nitro plugin to customize the behavior of any client:

Client-side hooks examples

export default defineNuxtPlugin((app) => {
  app.hooks.hook('storefront:client:configure', ({ config }) => {
    // Modify the config of the client before it is created
    config.logger = logContent => console.log(logContent)
  })

  app.hooks.hook('storefront:client:create', ({ client }) => {
    console.log('Storefront client created:', client)
  })

  app.hooks.hook('storefront:client:request', ({ operation, options }) => {
    console.log('Storefront client request sent:', operation, options)
  })

  app.hooks.hook('storefront:client:response', ({ response, operation, options }) => {
    console.log('Storefront client response received:', response, operation, options)
  })

  app.hooks.hook('storefront:client:errors', ({ errors }) => {
    console.log('Storefront client errors:', errors)
  })
})

Server-side hooks examples

export default defineNitroPlugin((app) => {
  app.hooks.hook('storefront:client:configure', ({ config }) => {
    // Modify the config of the client before it is created
    config.logger = logContent => console.log(logContent)
  })

  app.hooks.hook('storefront:client:create', ({ client }) => {
    console.log('Storefront client created:', client)
  })

  app.hooks.hook('storefront:client:request', ({ operation, options }) => {
    console.log('Storefront client request sent:', operation, options)
  })

  app.hooks.hook('storefront:client:response', ({ response, operation, options }) => {
    console.log('Storefront client response received:', response, operation, options)
  })

  app.hooks.hook('storefront:client:errors', ({ errors }) => {
    console.log('Storefront client errors:', errors)
  })
})

Customer account auth hooks

The customer account authentication flow runs entirely on the server, so these hooks are only available in a Nitro plugin. Use them to customize the OAuth request, run side effects on login/logout, or observe token refreshes.

~/server/plugins/customer-account-auth.ts
export default defineNitroPlugin((app) => {
  app.hooks.hook('customer-account:auth:authorize', ({ params }) => {
    // Mutate the authorization request, e.g. request a localized login screen
    params.locale = 'en'
  })

  app.hooks.hook('customer-account:auth:success', ({ user, tokens }) => {
    // React to a successful login (merge the guest cart, track analytics, ...)
    console.log('Customer logged in:', user.email)
  })

  app.hooks.hook('customer-account:auth:refresh', ({ tokens }) => {
    console.log('Access token refreshed, expires at:', tokens.expiresAt)
  })

  app.hooks.hook('customer-account:auth:logout', ({ user }) => {
    console.log('Customer logged out:', user?.email)
  })

  app.hooks.hook('customer-account:auth:error', ({ error }) => {
    console.error('Customer account OAuth failed:', error)
  })
})

Admin auth hooks

The admin API authenticates with a machine-to-machine OAuth flow (client credentials, with refresh token rotation), so these hooks are only available in a Nitro plugin. Use them to customize the token request, or to observe when an access token is issued, refreshed, or fails to issue.

These hooks only fire when the module obtains a token on your behalf. They are skipped when a static accessToken is configured.

~/server/plugins/admin-auth.ts
export default defineNitroPlugin((app) => {
  app.hooks.hook('admin:auth:request', ({ params }) => {
    // Mutate the token request body before it is sent
    params.scope = 'my-custom-scope'
  })

  app.hooks.hook('admin:auth:success', ({ token }) => {
    // React to a freshly issued access token (client credentials grant)
    console.log('Admin access token obtained, expires at:', token.expiresAt)
  })

  app.hooks.hook('admin:auth:refresh', ({ token }) => {
    console.log('Admin access token refreshed, expires at:', token.expiresAt)
  })

  app.hooks.hook('admin:auth:error', ({ error }) => {
    console.error('Admin token request failed:', error)
  })
})

Hooks reference

Hooks allows you to hook into the different stages of the module lifecycle.

Nuxt Hooks (Build Time)

HookArgumentsEnvironmentsDescription
shopify:confignuxt, configServerCalled before the parsed module config is persisted into the runtime config
shopify:setupnuxt, configServerCalled after the module setup is completed
storefront:generate:introspectionnuxt, configServerCalled before the storefront introspection schema is generated
storefront:generate:typesnuxt, configServerCalled before the storefront types are generated
storefront:generate:operationsnuxt, configServerCalled before the storefront operations are generated
customer-account:generate:introspectionnuxt, configServerCalled before the customer account introspection schema is generated
customer-account:generate:typesnuxt, configServerCalled before the customer account types are generated
customer-account:generate:operationsnuxt, configServerCalled before the customer account operations are generated
admin:generate:introspectionnuxt, configServerCalled before the admin introspection schema is generated
admin:generate:typesnuxt, configServerCalled before the admin types are generated
admin:generate:operationsnuxt, configServerCalled before the admin operations are generated

App Hooks (Runtime)

HookArgumentsEnvironmentsDescription
analytics:readyshopClientCalled once analytics is ready and the shop analytics are resolved
analytics:publishevent, payloadClientCalled whenever an analytics event is published
storefront:client:configureconfigServer & ClientCalled before the storefront client is created
storefront:client:createclientServer & ClientCalled after the storefront client is created
storefront:client:requestoperation, optionsServer & ClientCalled before the storefront client sends a request
storefront:client:responseresponse, operation, optionsServer & ClientCalled after the storefront client receives a response
storefront:client:errorserrorsServer & ClientCalled when a storefront client request contains errors
customer-account:client:configureconfigServer & ClientCalled before the customer account client is created
customer-account:client:createclientServer & ClientCalled after the customer account client is created
customer-account:client:requestoperation, optionsServer & ClientCalled before the customer account client sends a request
customer-account:client:responseresponse, operation, optionsServer & ClientCalled after the customer account client receives a response
customer-account:client:errorserrorsServer & ClientCalled when a customer account client request contains errors

Server Hooks (Runtime)

HookArgumentsEnvironmentsDescription
storefront:client:configureconfigServerCalled before the storefront client is created
storefront:client:createclientServerCalled after the storefront client is created
storefront:client:requestoperation, optionsServerCalled before the storefront client sends a request
storefront:client:responseresponse, operation, optionsServerCalled after the storefront client receives a response
storefront:client:errorserrorsServerCalled when a storefront client request contains errors
customer-account:client:configureconfigServerCalled before the customer account client is created
customer-account:client:createclientServerCalled after the customer account client is created
customer-account:client:requestoperation, optionsServerCalled before the customer account client sends a request
customer-account:client:responseresponse, operation, optionsServerCalled after the customer account client receives a response
customer-account:client:errorserrorsServerCalled when a customer account client request contains errors
customer-account:auth:authorizeparamsServerCalled before redirecting to Shopify to start the OAuth flow (mutable params)
customer-account:auth:successuser, tokensServerCalled after a successful login, before the session is persisted
customer-account:auth:refreshtokensServerCalled after the customer account access token is refreshed
customer-account:auth:logoutuser, idTokenServerCalled before the session is cleared on logout
customer-account:auth:errorerrorServerCalled when the customer account OAuth flow fails
admin:auth:requestparamsServerCalled before the admin access token request is sent (mutable params)
admin:auth:successtokenServerCalled after an admin access token is obtained (client credentials grant)
admin:auth:refreshtokenServerCalled after the admin access token is refreshed (refresh token grant)
admin:auth:errorerrorServerCalled when the admin access token request fails
admin:client:configureconfigServerCalled before the admin client is created
admin:client:createclientServerCalled after the admin client is created
admin:client:requestoperation, optionsServerCalled before the admin client sends a request
admin:client:responseresponse, operation, optionsServerCalled after the admin client receives a response
admin:client:errorserrorsServerCalled when an admin client request contains errors
Copyright © 2026