Skip to content

Commit aef9205

Browse files
waleedlatif1claude
andcommitted
fix(quickbooks): persist realm scope on re-auth, type itemId as required
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 28b40bd commit aef9205

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

apps/sim/lib/auth/auth.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,17 +533,30 @@ export const auth = betterAuth({
533533
}
534534

535535
if (account.providerId === 'quickbooks') {
536+
const updates: {
537+
accessTokenExpiresAt?: Date
538+
scope?: string
539+
} = {}
540+
541+
let realmId: string | undefined
536542
try {
537543
const cookieStore = await cookies()
544+
realmId = cookieStore.get('qb_pending_realm')?.value
538545
cookieStore.delete('qb_pending_realm')
539546
} catch (error) {
540-
logger.error('Failed to clear qb_pending_realm cookie', { error })
547+
logger.error('Failed to read/clear qb_pending_realm cookie', { error })
541548
}
549+
542550
if (!account.accessTokenExpiresAt) {
543-
await db
544-
.update(schema.account)
545-
.set({ accessTokenExpiresAt: new Date(Date.now() + 60 * 60 * 1000) })
546-
.where(eq(schema.account.id, account.id))
551+
updates.accessTokenExpiresAt = new Date(Date.now() + 60 * 60 * 1000)
552+
}
553+
554+
if (realmId && !account.scope?.includes('__qb_realm__:')) {
555+
updates.scope = `__qb_realm__:${realmId} ${account.scope ?? ''}`.trim()
556+
}
557+
558+
if (Object.keys(updates).length > 0) {
559+
await db.update(schema.account).set(updates).where(eq(schema.account.id, account.id))
547560
}
548561
}
549562

apps/sim/tools/quickbooks/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface QuickBooksLineItem {
3333
description?: string
3434
amount: number
3535
quantity?: number
36-
itemId?: string
36+
itemId: string
3737
itemName?: string
3838
}
3939

0 commit comments

Comments
 (0)