@@ -97,7 +97,7 @@ import {
9797import { PlatformEvents } from '@/lib/core/telemetry'
9898import { getBaseUrl , isLocalhostUrl , parseOriginList } from '@/lib/core/utils/urls'
9999import {
100- parseCredentialDraftIdFromCallbackUrl ,
100+ loadOAuthCredentialDraftBinding ,
101101 processCredentialDraft ,
102102} from '@/lib/credentials/draft-processor'
103103import { sendEmail } from '@/lib/messaging/email/mailer'
@@ -526,33 +526,33 @@ export const auth = betterAuth({
526526 }
527527 }
528528
529- let credentialDraftId : string | undefined
530- try {
531- const oauthState = await getOAuthState ( )
532- credentialDraftId = parseCredentialDraftIdFromCallbackUrl ( oauthState ?. callbackURL )
533- } catch ( error ) {
529+ const credentialDraftBinding = await loadOAuthCredentialDraftBinding ( ( ) =>
530+ getOAuthState ( )
531+ )
532+ if ( credentialDraftBinding . status === 'unavailable' ) {
534533 logger . error ( '[account.create.after] Failed to read OAuth credential draft state' , {
535534 userId : account . userId ,
536535 providerId : account . providerId ,
537- error,
536+ error : credentialDraftBinding . error ,
538537 } )
539- throw error
540538 }
541539
542- try {
543- await processCredentialDraft ( {
544- draftId : credentialDraftId ,
545- userId : account . userId ,
546- providerId : account . providerId ,
547- accountId : account . id ,
548- } )
549- } catch ( error ) {
550- logger . error ( '[account.create.after] Failed to process credential draft' , {
551- userId : account . userId ,
552- providerId : account . providerId ,
553- error,
554- } )
555- if ( credentialDraftId ) throw error
540+ if ( credentialDraftBinding . status === 'available' ) {
541+ try {
542+ await processCredentialDraft ( {
543+ draftId : credentialDraftBinding . draftId ,
544+ userId : account . userId ,
545+ providerId : account . providerId ,
546+ accountId : account . id ,
547+ } )
548+ } catch ( error ) {
549+ logger . error ( '[account.create.after] Failed to process credential draft' , {
550+ userId : account . userId ,
551+ providerId : account . providerId ,
552+ error,
553+ } )
554+ if ( credentialDraftBinding . draftId ) throw error
555+ }
556556 }
557557
558558 try {
0 commit comments