Hooks
The @scayle/storefront-nuxt
provides Nitro runtime hooks, allowing you to extend the NPM package functionality by executing custom logic during specific events.
Compared to overriding RPCs with a custom implementation, hooks offer a less intrusive way to extend RPC logic without fully redefining existing behavior. These hooks can be registered within a Nitro plugin in your Storefront Application.
Example
Hook | Arguments | Description |
---|---|---|
storefront:context:created | rpcContext | Called after the rpcContext has been initialized and created. |
storefront:rpc:before | rpcName, rpcContext, rpcPayload | Called before an RPC method is executed. |
storefront:rpc:after | rpcName, rpcContext, rpcResult | Called after an RPC method has been successfully executed. |
storefront:rpc:error | rpcName, rpcContext, error | Called when an error is thrown during the execution of an RPC method. |
storefront:afterLogin | { shopId, user, authenticationType, accessToken }, rpcContext | Called after a user has successfully logged in. |
storefront:afterLogout | { shopId, user, authenticationType }, rpcContext | Called after a user has successfully logged out. |