Skip to content

Module hooks

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.

ts
// ~/server/plugins/your-plugin.ts

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

    nitroApp.hooks.hook('storefont:client:create', ({ client }) => {
        // Do something with the client after it is created
        console.log('Storefront client created:', client)
    })

    nitroApp.hooks.hook('storefont:client:request', ({ operation, options }) => {
        // Do something with the operation and options before the request is sent
        console.log('Storefront client request sent:', operation, options)
    })

    nitroApp.hooks.hook('storefont:client:response', ({ response, operation, options }) => {
        // Do something with the response, operations and options after a response is received
        console.log('Storefront client response received:', response, operation, options)
    })

    nitroApp.hooks.hook('storefont:client:errors', ({ errors }) => {
        // Do something with the errors
        console.log('Storefront client errors:', errors)
    })
})

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
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
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
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

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
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

Released under the MIT License.