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
})
})
Hook | Arguments | Description |
---|---|---|
storefront:context:created | rpcContext | Called after the rpcContext was created |
storefront:rpc:before | rpcName, rpcContext, rpcPayload | Called before an RPC was executed |
storefront:rpc:after | rpcName, rpcContext, rpcResult | Called after an RPC was executed |
storefront:rpc:error | rpcName, rpcContext, error | Called 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 |