File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments