Skip to content

Commit 1c10642

Browse files
committed
feat: update customer account config
Signed-off-by: Frederik Bußmann <frederik@bussmann.io>
1 parent 2ac4b5a commit 1c10642

8 files changed

Lines changed: 403 additions & 233 deletions

File tree

bun.lock

Lines changed: 357 additions & 223 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/2.essentials/2.configuration.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Configure one or more API clients:
170170
Use mock.shop instead of your actual store - default: `false`
171171
:::
172172

173-
:::field{name="proxy" type="boolean | string"}
173+
:::field{name="proxy" type="boolean | object"}
174174
Proxy all client-side requests through Nitro. Use `true` for default path or provide custom path - default: `true`
175175
:::
176176

@@ -230,7 +230,23 @@ Configure one or more API clients:
230230
Client ID for customer account API requests
231231
:::
232232

233-
:::field{name="proxy" type="boolean | string"}
233+
:::field{name="scope" type="array"}
234+
OAuth scopes to request during authentication - default: `['openid', 'email', 'customer-account-api:full']`
235+
:::
236+
237+
:::field{name="loginURL" type="string"}
238+
Login URL for customer account API authentication - default: `/_auth/customer-account/callback`
239+
:::
240+
241+
:::field{name="logoutURL" type="string"}
242+
Logout URL for customer account API authentication - default: `/_auth/customer-account/logout`
243+
:::
244+
245+
:::field{name="redirectURL" type="string"}
246+
Redirect URL for customer account API authentication
247+
:::
248+
249+
:::field{name="proxy" type="boolean | object"}
234250
Proxy all client-side requests through Nitro. Use `true` for default path or provide custom path - default: `true`
235251
:::
236252

@@ -369,7 +385,9 @@ export default defineNuxtConfig({
369385
publicAccessToken: "YOUR_PUBLIC_ACCESS_TOKEN",
370386
privateAccessToken: "YOUR_PRIVATE_ACCESS_TOKEN",
371387
mock: false,
372-
proxy: true,
388+
proxy: {
389+
path: "/_proxy/storefront",
390+
},
373391
sandbox: true,
374392
autoImport: true,
375393
codegen: {
@@ -398,7 +416,12 @@ export default defineNuxtConfig({
398416
customerAccount: {
399417
apiVersion: "2026-01",
400418
clientId: "YOUR_CLIENT_ID",
401-
proxy: true,
419+
scope: ["openid", "email", "customer-account-api:full"],
420+
loginURL: "/_auth/customer-account/callback",
421+
logoutURL: "/_auth/customer-account/logout",
422+
proxy: {
423+
path: "/_proxy/customer-account",
424+
},
402425
sandbox: true,
403426
autoImport: true,
404427
codegen: {
@@ -418,7 +441,9 @@ export default defineNuxtConfig({
418441
clientSecret: "YOUR_ADMIN_CLIENT_SECRET",
419442
accessToken: "YOUR_ADMIN_ACCESS_TOKEN",
420443
refreshToken: "YOUR_ADMIN_REFRESH_TOKEN",
421-
tokenStorage: true,
444+
tokenStorage: {
445+
driver: "memory"
446+
},
422447
sandbox: true,
423448
autoImport: false,
424449
codegen: {

docs/content/2.essentials/4.customer-account.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ function login() {
6262
</template>
6363
```
6464

65+
::tip
66+
You can change the default authentication routes in the module configuration if you want to use different URLs for the login and logout routes.
67+
::
68+
6569
### Logging out
6670

6771
To log the user out, redirect them to `/_auth/customer-account/logout`:

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@
115115
"@nuxt/eslint-config": "^1.15.2",
116116
"@nuxt/module-builder": "^1.0.2",
117117
"@nuxt/schema": "^4.4.2",
118-
"@nuxt/test-utils": "^4.0.2",
118+
"@nuxt/test-utils": "^4.0.3",
119119
"@shopify/hydrogen": "^2026.4.2",
120120
"@types/bun": "^1.3.13",
121121
"@types/node": "^25.6.0",
122122
"@vitest/coverage-v8": "^4.1.5",
123123
"eslint": "^10.2.1",
124124
"happy-dom": "^20.9.0",
125-
"knip": "^6.7.0",
125+
"knip": "^6.8.0",
126126
"nuxt": "^4.4.2",
127127
"nuxt-auth-utils": "^0.5.29",
128128
"typescript": "^6.0.3",

src/schemas/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export const customerAccountClientSchema = clientSchema.extend({
4646
clientId: z.string(),
4747
scope: z.array(z.string()).optional(),
4848
redirectURL: z.string().optional(),
49+
loginURL: z.string().optional(),
50+
logoutURL: z.string().optional(),
4951
proxy: z.object({
5052
path: z.string().optional(),
5153
}).or(z.boolean()).optional(),

src/schemas/runtime.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ const customerAccountClientSchemaWithDefaults = clientSchemaWithDefaults.omit({
120120
scope: customerAccountClientSchema.shape.scope,
121121
redirectURL: customerAccountClientSchema.shape.redirectURL,
122122

123+
loginURL: customerAccountClientSchema.shape.loginURL.default('_auth/customer-account/callback'),
124+
logoutURL: customerAccountClientSchema.shape.logoutURL.default('_auth/customer-account/logout'),
125+
123126
documents: customerAccountClientSchema.shape.documents.transform(v => v ? v : defaultCustomerAccountDocuments),
124127
proxy: customerAccountClientSchema.shape.proxy.default({ path: '_proxy/customer-account' }).transform(v => typeof v === 'undefined' || v === true ? { path: '_proxy/customer-account' } : v),
125128
})

src/setup/clients.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ShopifyConfig } from '../types'
55

66
import { addServerHandler, addServerImports, addTemplate, addTypeTemplate, hasNuxtModule } from '@nuxt/kit'
77
import defu from 'defu'
8-
import { withoutProtocol } from 'ufo'
8+
import { withLeadingSlash, withoutProtocol } from 'ufo'
99

1010
import { useLogger } from '../utils/log'
1111
import {
@@ -64,13 +64,13 @@ export default async function setupClients(nuxt: Nuxt, config: ShopifyConfig, re
6464

6565
addServerHandler({
6666
method: 'get',
67-
route: '/_auth/customer-account/callback',
67+
route: withLeadingSlash(config.clients[clientType]?.loginURL),
6868
handler: resolver.resolve('./runtime/server/api/auth/customer-account/callback'),
6969
})
7070

7171
addServerHandler({
7272
method: 'get',
73-
route: '/_auth/customer-account/logout',
73+
route: withLeadingSlash(config.clients[clientType]?.logoutURL),
7474
handler: resolver.resolve('./runtime/server/api/auth/customer-account/logout'),
7575
})
7676

test/v4.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ describe('test module with nuxt 4', async () => {
8282
apiVersion: process.env.NUXT_SHOPIFY_CLIENTS_CUSTOMER_ACCOUNT_API_VERSION,
8383
clientId: process.env.NUXT_SHOPIFY_CLIENTS_CUSTOMER_ACCOUNT_CLIENT_ID,
8484
documents: expectedCustomerAccountDocuments,
85+
loginURL: '_auth/customer-account/callback',
86+
logoutURL: '_auth/customer-account/logout',
8587
proxy: {
8688
path: '_proxy/customer-account',
8789
},

0 commit comments

Comments
 (0)