docs
  1. SCAYLE Resource Center
  2. Developer Guide
  3. Basic Setup
  4. Hooks

Hooks

@scayle/storefront-nuxt provides Nitro runtime hooks to extend the NPM package's functionality by allowing the execution of custom logic during specific events.

Compared to overwriting RPCs with a custom implementation, hooks let you extend RPC logic without redefining existing behavior.

These hooks can be registered within a Nitro plugin.

import { defineNitroPlugin } from '#imports'

export default defineNitroPlugin((nitroApp) => {
  nitroApp.hooks.hook('storefront:rpc:after', (name, context, result) => {
    if(name !== 'getOrderDataByCbd') return 
    // refresh user data
  })
})
HookArgumentsDescription
storefront:context:createdrpcContextCalled after the rpcContext was created
storefront:rpc:beforerpcName, rpcContext, rpcPayloadCalled before an RPC was executed
storefront:rpc:afterrpcName, rpcContext, rpcResultCalled after an RPC was executed
storefront:rpc:errorrpcName, rpcContext, errorCalled when an error was thrown during RPC
storefront:afterLogin{ shopId, user, authenticationType, accessToken }, rpcContext Called after a user successfully logged in
storefront:afterLogout{ shopId, user, authenticationType }, rpcContext Called after a user successfully logged out