@@ -149,6 +149,66 @@ export default defineNitroPlugin((app) => {
149149```
150150::
151151
152+ ### Customer account auth hooks
153+
154+ The customer account authentication flow runs entirely on the server, so these hooks are only available in a Nitro plugin.
155+ Use them to customize the OAuth request, run side effects on login/logout, or observe token refreshes.
156+
157+ ``` ts [~/server/plugins/customer-account-auth.ts]
158+ export default defineNitroPlugin ((app ) => {
159+ app .hooks .hook (' customer-account:auth:authorize' , ({ params }) => {
160+ // Mutate the authorization request, e.g. request a localized login screen
161+ params .locale = ' en'
162+ })
163+
164+ app .hooks .hook (' customer-account:auth:success' , ({ user , tokens }) => {
165+ // React to a successful login (merge the guest cart, track analytics, ...)
166+ console .log (' Customer logged in:' , user .email )
167+ })
168+
169+ app .hooks .hook (' customer-account:auth:refresh' , ({ tokens }) => {
170+ console .log (' Access token refreshed, expires at:' , tokens .expiresAt )
171+ })
172+
173+ app .hooks .hook (' customer-account:auth:logout' , ({ user }) => {
174+ console .log (' Customer logged out:' , user ?.email )
175+ })
176+
177+ app .hooks .hook (' customer-account:auth:error' , ({ error }) => {
178+ console .error (' Customer account OAuth failed:' , error )
179+ })
180+ })
181+ ```
182+
183+ ### Admin auth hooks
184+
185+ 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.
186+ Use them to customize the token request, or to observe when an access token is issued, refreshed, or fails to issue.
187+
188+ These hooks only fire when the module obtains a token on your behalf. They are skipped when a static ` accessToken ` is configured.
189+
190+ ``` ts [~/server/plugins/admin-auth.ts]
191+ export default defineNitroPlugin ((app ) => {
192+ app .hooks .hook (' admin:auth:request' , ({ params }) => {
193+ // Mutate the token request body before it is sent
194+ params .scope = ' my-custom-scope'
195+ })
196+
197+ app .hooks .hook (' admin:auth:success' , ({ token }) => {
198+ // React to a freshly issued access token (client credentials grant)
199+ console .log (' Admin access token obtained, expires at:' , token .expiresAt )
200+ })
201+
202+ app .hooks .hook (' admin:auth:refresh' , ({ token }) => {
203+ console .log (' Admin access token refreshed, expires at:' , token .expiresAt )
204+ })
205+
206+ app .hooks .hook (' admin:auth:error' , ({ error }) => {
207+ console .error (' Admin token request failed:' , error )
208+ })
209+ })
210+ ```
211+
152212## Hooks reference
153213
154214Hooks allows you to hook into the different stages of the module lifecycle.
@@ -185,20 +245,29 @@ Hooks allows you to hook into the different stages of the module lifecycle.
185245
186246### Server Hooks (Runtime)
187247
188- | Hook | Arguments | Environments | Description |
189- | ----------------------------------- | :--------------------------------: | :----------: | ------------------------------------------------------------- |
190- | ` storefront:client:configure ` | ` config ` | Server | Called before the storefront client is created |
191- | ` storefront:client:create ` | ` client ` | Server | Called after the storefront client is created |
192- | ` storefront:client:request ` | ` operation ` , ` options ` | Server | Called before the storefront client sends a request |
193- | ` storefront:client:response ` | ` response ` , ` operation ` , ` options ` | Server | Called after the storefront client receives a response |
194- | ` storefront:client:errors ` | ` errors ` | Server | Called when a storefront client request contains errors |
195- | ` customer-account:client:configure ` | ` config ` | Server | Called before the customer account client is created |
196- | ` customer-account:client:create ` | ` client ` | Server | Called after the customer account client is created |
197- | ` customer-account:client:request ` | ` operation ` , ` options ` | Server | Called before the customer account client sends a request |
198- | ` customer-account:client:response ` | ` response ` , ` operation ` , ` options ` | Server | Called after the customer account client receives a response |
199- | ` customer-account:client:errors ` | ` errors ` | Server | Called when a customer account client request contains errors |
200- | ` admin:client:configure ` | ` config ` | Server | Called before the admin client is created |
201- | ` admin:client:create ` | ` client ` | Server | Called after the admin client is created |
202- | ` admin:client:request ` | ` operation ` , ` options ` | Server | Called before the admin client sends a request |
203- | ` admin:client:response ` | ` response ` , ` operation ` , ` options ` | Server | Called after the admin client receives a response |
204- | ` admin:client:errors ` | ` errors ` | Server | Called when an admin client request contains errors |
248+ | Hook | Arguments | Environments | Description |
249+ | ----------------------------------- | :--------------------------------: | :----------: | ------------------------------------------------------------------------------- |
250+ | ` storefront:client:configure ` | ` config ` | Server | Called before the storefront client is created |
251+ | ` storefront:client:create ` | ` client ` | Server | Called after the storefront client is created |
252+ | ` storefront:client:request ` | ` operation ` , ` options ` | Server | Called before the storefront client sends a request |
253+ | ` storefront:client:response ` | ` response ` , ` operation ` , ` options ` | Server | Called after the storefront client receives a response |
254+ | ` storefront:client:errors ` | ` errors ` | Server | Called when a storefront client request contains errors |
255+ | ` customer-account:client:configure ` | ` config ` | Server | Called before the customer account client is created |
256+ | ` customer-account:client:create ` | ` client ` | Server | Called after the customer account client is created |
257+ | ` customer-account:client:request ` | ` operation ` , ` options ` | Server | Called before the customer account client sends a request |
258+ | ` customer-account:client:response ` | ` response ` , ` operation ` , ` options ` | Server | Called after the customer account client receives a response |
259+ | ` customer-account:client:errors ` | ` errors ` | Server | Called when a customer account client request contains errors |
260+ | ` customer-account:auth:authorize ` | ` params ` | Server | Called before redirecting to Shopify to start the OAuth flow (mutable ` params ` ) |
261+ | ` customer-account:auth:success ` | ` user ` , ` tokens ` | Server | Called after a successful login, before the session is persisted |
262+ | ` customer-account:auth:refresh ` | ` tokens ` | Server | Called after the customer account access token is refreshed |
263+ | ` customer-account:auth:logout ` | ` user ` , ` idToken ` | Server | Called before the session is cleared on logout |
264+ | ` customer-account:auth:error ` | ` error ` | Server | Called when the customer account OAuth flow fails |
265+ | ` admin:auth:request ` | ` params ` | Server | Called before the admin access token request is sent (mutable ` params ` ) |
266+ | ` admin:auth:success ` | ` token ` | Server | Called after an admin access token is obtained (client credentials grant) |
267+ | ` admin:auth:refresh ` | ` token ` | Server | Called after the admin access token is refreshed (refresh token grant) |
268+ | ` admin:auth:error ` | ` error ` | Server | Called when the admin access token request fails |
269+ | ` admin:client:configure ` | ` config ` | Server | Called before the admin client is created |
270+ | ` admin:client:create ` | ` client ` | Server | Called after the admin client is created |
271+ | ` admin:client:request ` | ` operation ` , ` options ` | Server | Called before the admin client sends a request |
272+ | ` admin:client:response ` | ` response ` , ` operation ` , ` options ` | Server | Called after the admin client receives a response |
273+ | ` admin:client:errors ` | ` errors ` | Server | Called when an admin client request contains errors |
0 commit comments