Skip to content

Commit 725e585

Browse files
committed
fix: fix nuxt-auth-utils stubs for customer account api
Signed-off-by: Frederik Bußmann <frederik@bussmann.io>
1 parent c3578ec commit 725e585

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

playgrounds/playground-v4/app/pages/customer.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<script setup lang="ts">
2-
import type { Customer } from '#shopify/storefront'
2+
import type { CustomerDetailsQuery } from '#shopify/customer-account'
33
44
const session = useUserSession()
55
6-
let customer: Partial<Customer> | undefined = undefined
6+
let customer: CustomerDetailsQuery['customer'] | undefined = undefined
77
88
if (!session.loggedIn) {
99
navigateTo('/_auth/customer-account/callback')
@@ -26,6 +26,7 @@ else {
2626

2727
<template>
2828
<div>
29-
<pre>{{ customer?.firstName }} {{ customer?.lastName }}</pre>
29+
<h1>Welcome, {{ customer?.firstName && customer?.lastName ? `${customer.firstName} ${customer.lastName}` : 'Nuxt User' }}!</h1>
30+
<p>E-Mail: {{ customer?.emailAddress?.emailAddress }}</p>
3031
</div>
3132
</template>

playgrounds/playground-v4/graphql/customer-account/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ export const CUSTOMER_FRAGMENT = `#graphql
33
id
44
firstName
55
lastName
6+
emailAddress {
7+
emailAddress
8+
}
69
}
710
`

src/module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export default defineNuxtModule<ModuleOptions>({
3131
},
3232

3333
moduleDependencies: {
34-
'nuxt-auth-utils': {},
34+
'nuxt-auth-utils': {
35+
optional: true,
36+
},
3537
},
3638

3739
async setup(options, nuxt) {

src/setup/clients.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Nuxt } from '@nuxt/schema'
33

44
import type { ShopifyConfig } from '../types'
55

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

@@ -17,7 +17,7 @@ import {
1717
} from '../utils/clients'
1818
import { ShopifyClientType } from '../schemas'
1919
import { createStoreDomain } from '../runtime/utils/client'
20-
import { nuxtAuthUtilsTemplate } from '../templates/auth-utils'
20+
import { nuxtAuthUtilsDevTemplate, nuxtAuthUtilsTemplate } from '../templates/auth-utils'
2121

2222
export default async function setupClients(nuxt: Nuxt, config: ShopifyConfig, resolver: Resolver) {
2323
const logger = useLogger(config)
@@ -83,4 +83,20 @@ export default async function setupClients(nuxt: Nuxt, config: ShopifyConfig, re
8383
})
8484
}
8585
}
86+
87+
if (!hasNuxtModule('nuxt-auth-utils', nuxt)) {
88+
addTypeTemplate({
89+
filename: 'shopify/auth-utils.dev.d.ts',
90+
getContents: () => nuxtAuthUtilsDevTemplate,
91+
}, {
92+
nitro: true,
93+
})
94+
95+
const { dst } = addTemplate({
96+
filename: 'shopify/auth-utils.mjs',
97+
getContents: () => 'export const getUserSession = async () => {}',
98+
})
99+
100+
addServerImports([{ from: resolver.resolve(dst), name: 'getUserSession' }])
101+
}
86102
}

0 commit comments

Comments
 (0)