[GH-ISSUE #2297] Issue when linking some Google accounts #9137

Closed
opened 2026-04-13 04:29:24 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @Et3rnel on GitHub (Apr 15, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2297

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Try account linking with different Youtube accounts (Google credentials) with Youtube scopes

Current vs. Expected behavior

Account linking of different Youtube accounts work well.

What version of Better Auth are you using?

1.2.6

Provide environment information

- Macbook Air M2
- Brave browser

Which area(s) are affected? (Select all that apply)

Other

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { customSession } from "better-auth/plugins";
import { db } from "@/src/db/drizzle";
import { user, session, account, verification } from "@/src/db/schema";
import { EmailDispatcher } from "@/infrastructure/dispatcher/email-dispatcher";
import { UpdateAccountYoutubeDetailsCommand, UpdateAccountYoutubeDetailsCommandHandler } from '@/application/command/update-account-name-for-youtube-command';
 
export const auth = betterAuth({
    // Email and password authentication
    emailAndPassword: {  
        enabled: true
    },
    accountLinking: {
        allowDifferentEmails: true,
        enabled: true,
        trustedProviders: ["google"] // For YouTube channels linking,
    },
    // For YouTube channels linking
    socialProviders: {
        google: { 
            clientId: process.env.GOOGLE_CLIENT_ID, 
            clientSecret: process.env.GOOGLE_CLIENT_SECRET,
            // Forces re-consent, showing the permissions screen again
            prompt: 'consent', 
        }, 
    },

    // Database driver
    database: drizzleAdapter(db, {
        provider: "pg",
        schema: {
            user: user,
            session: session,
            account: account,
            verification: verification,
        },
    }),

    databaseHooks: {
        account: {
            create: {   
                after: async (account) => {
                    // Check if the account is from Google provider
                    if (account.providerId === 'google' && account.accessToken) {
                        try {
                            const command = new UpdateAccountYoutubeDetailsCommand(account.accountId, account.accessToken);
                            
                            const handler = new UpdateAccountYoutubeDetailsCommandHandler();
                            await handler.handle(command);
                        } catch (error) {
                            console.error('Error updating account name for YouTube account:', error);
                        }
                    }
                },
            },
        },
        user: {
            create: {
                after: async (user) => {
                    await EmailDispatcher.sendWelcomeEmail(user.name, user.email);
                },
            },
        }
    },


    // Augment the session with additional fields
    plugins: [
        customSession(async ({ user, session }) => {
            const { UserRepository } = await import('@/infrastructure/repository/user-repository');
            
            // Fetch the user
            const domainUser = await UserRepository.findById(user.id);
            
            return {
                user: domainUser || {
                    user, // Fallback to the user object if the user couldn't be fetched
                },
                session
            };
        }),
    ],
});

Additional context

Hi!
I'm having some issues using account linking features on some Google (with Youtube scopes) accounts. I could not find any differences between 2 Youtube accounts.

I'm stuck on the Google screen with an infinite loading:
Image

I have some errors if I open the developer tools in a Brave browser:

Failed to load resource: the server responded with a status of 401 ()

And also this error:

m=byfTOb,lsjVmc,LEikZe:34 Uncaught (in promise) 
_.Rt
Vl
: 
Dt {da: Jt, aa: 103, Ea: false, ka: undefined, ha: "Incomplete XSS header at end of request (HTTP Stat…(XHR Error Code: 6) (XHR Error Message: ' [401]')"}
aa
: 
true
da
: 
103
message
: 
"Error code = 103, Path = /_/OAuthUi/data/batchexecute, Message = There was an error during the transport or processing of this request., Incomplete XSS header at end of request (HTTP Status: 401) (XHR Error Code: 6) (XHR Error Message: ' [401]')"
name
: 
"TransportError"
stack
: 
"TransportError: Error code = 103, Path = /_/OAuthUi/data/batchexecute, Message = There was an error during the transport or processing of this request., Incomplete XSS header at end of request (HTTP Status: 401) (XHR Error Code: 6) (XHR Error Message: ' [401]')\n    at new _.Rt (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/ck=boq-identity.OAuthUi.KYNwTDFUaBY.L.B1.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/exm=_b,_tp/excm=_b,_tp,attributesview/ed=1/wt=2/ujg=1/rs=AOaEmlHwXsq4wDVjt23RuU0nuRoYW25AKg/ee=ASJRFf:DAnQ7e;Al0B8:kibjWe;DaIJ8c:iAskyc;EVNhjf:pw70Gc;EkYFhd:GwYlN;EmZ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9Tlc;dIoSBb:SpsfSb;dowIGb:ebZ3mb;eBAeSb:zbML3c;iFQyKf:vfuNJf;lOO0Vd:OTA3Ae;nAFL3:NTMZac;nTuGK:JKNPM;oGtAuc:sOXFj;oSUNyd:K0PMbc;oXZmbc:tUnxGc;pXdRYb:L9OGUe;qafBPd:yDVVkb;qddgKe:xQtZb;vNjB7d:YTxL4;wR5FRb:siKnQd;yxTchf:KUM7Z/m=byfTOb,lsjVmc,LEikZe:75:440)\n    at Nfa (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:240:247)\n    at Ik (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:237:47)\n    at Object.Ob (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:236:471)\n    at Nfa (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:240:247)\n    at Ik (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:237:47)\n    at _.Tf.aa (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:237:216)\n    at Nfa (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:240:247)\n    at Ik (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:237:47)"
[[Prototype]]
: 
Error
constructor
: 
ƒ (a,b,c,d,e)
getError
: 
ƒ ()
[[Prototype]]
: 
Error

Do you have any clue where it could come from?
With my other Youtube account (on the same mail), I don't have any issue.

Originally created by @Et3rnel on GitHub (Apr 15, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2297 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Try account linking with different Youtube accounts (Google credentials) with Youtube scopes ### Current vs. Expected behavior Account linking of different Youtube accounts work well. ### What version of Better Auth are you using? 1.2.6 ### Provide environment information ```bash - Macbook Air M2 - Brave browser ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { customSession } from "better-auth/plugins"; import { db } from "@/src/db/drizzle"; import { user, session, account, verification } from "@/src/db/schema"; import { EmailDispatcher } from "@/infrastructure/dispatcher/email-dispatcher"; import { UpdateAccountYoutubeDetailsCommand, UpdateAccountYoutubeDetailsCommandHandler } from '@/application/command/update-account-name-for-youtube-command'; export const auth = betterAuth({ // Email and password authentication emailAndPassword: { enabled: true }, accountLinking: { allowDifferentEmails: true, enabled: true, trustedProviders: ["google"] // For YouTube channels linking, }, // For YouTube channels linking socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, // Forces re-consent, showing the permissions screen again prompt: 'consent', }, }, // Database driver database: drizzleAdapter(db, { provider: "pg", schema: { user: user, session: session, account: account, verification: verification, }, }), databaseHooks: { account: { create: { after: async (account) => { // Check if the account is from Google provider if (account.providerId === 'google' && account.accessToken) { try { const command = new UpdateAccountYoutubeDetailsCommand(account.accountId, account.accessToken); const handler = new UpdateAccountYoutubeDetailsCommandHandler(); await handler.handle(command); } catch (error) { console.error('Error updating account name for YouTube account:', error); } } }, }, }, user: { create: { after: async (user) => { await EmailDispatcher.sendWelcomeEmail(user.name, user.email); }, }, } }, // Augment the session with additional fields plugins: [ customSession(async ({ user, session }) => { const { UserRepository } = await import('@/infrastructure/repository/user-repository'); // Fetch the user const domainUser = await UserRepository.findById(user.id); return { user: domainUser || { user, // Fallback to the user object if the user couldn't be fetched }, session }; }), ], }); ``` ### Additional context Hi! I'm having some issues using account linking features on some Google (with Youtube scopes) accounts. I could not find any differences between 2 Youtube accounts. I'm stuck on the Google screen with an infinite loading: <img width="1060" alt="Image" src="https://github.com/user-attachments/assets/45d7ecb2-da29-4dcb-be81-d139f73e0df7" /> I have some errors if I open the developer tools in a Brave browser: ```console Failed to load resource: the server responded with a status of 401 () ``` And also this error: ```console m=byfTOb,lsjVmc,LEikZe:34 Uncaught (in promise) _.Rt Vl : Dt {da: Jt, aa: 103, Ea: false, ka: undefined, ha: "Incomplete XSS header at end of request (HTTP Stat…(XHR Error Code: 6) (XHR Error Message: ' [401]')"} aa : true da : 103 message : "Error code = 103, Path = /_/OAuthUi/data/batchexecute, Message = There was an error during the transport or processing of this request., Incomplete XSS header at end of request (HTTP Status: 401) (XHR Error Code: 6) (XHR Error Message: ' [401]')" name : "TransportError" stack : "TransportError: Error code = 103, Path = /_/OAuthUi/data/batchexecute, Message = There was an error during the transport or processing of this request., Incomplete XSS header at end of request (HTTP Status: 401) (XHR Error Code: 6) (XHR Error Message: ' [401]')\n at new _.Rt (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/ck=boq-identity.OAuthUi.KYNwTDFUaBY.L.B1.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/exm=_b,_tp/excm=_b,_tp,attributesview/ed=1/wt=2/ujg=1/rs=AOaEmlHwXsq4wDVjt23RuU0nuRoYW25AKg/ee=ASJRFf:DAnQ7e;Al0B8:kibjWe;DaIJ8c:iAskyc;EVNhjf:pw70Gc;EkYFhd:GwYlN;EmZ2Bf:zr1jrb;JsbNhc:Xd8iUd;K5nYTd:ZDZcre;LBgRLc:XVMNvd;Me32dd:MEeYgc;NPKaK:PVlQOd;NSEoX:lazG7b;Pjplud:EEDORb;QGR0gd:Mlhmy;SMDL4c:K0PMbc;SNUn3:ZwDk9d;ScI3Yc:e7Hzgb;UpnZUd:nnwwYc;Uvc8o:VDovNc;XdiAjb:NLiXbe;YIZmRd:A1yn5d;a56pNe:JEfCwb;cEt90b:ws9Tlc;dIoSBb:SpsfSb;dowIGb:ebZ3mb;eBAeSb:zbML3c;iFQyKf:vfuNJf;lOO0Vd:OTA3Ae;nAFL3:NTMZac;nTuGK:JKNPM;oGtAuc:sOXFj;oSUNyd:K0PMbc;oXZmbc:tUnxGc;pXdRYb:L9OGUe;qafBPd:yDVVkb;qddgKe:xQtZb;vNjB7d:YTxL4;wR5FRb:siKnQd;yxTchf:KUM7Z/m=byfTOb,lsjVmc,LEikZe:34:329)\n at ou.Wa (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/ck=boq-identity.OAuthUi.KYNwTDFUaBY.L.B1.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/exm=_b,_tp/excm=_b,_tp,attributesview/ed=1/wt=2/ujg=1/rs=AOaEmlHwXsq4wDVjt23RuU0nuRoYW25AKg/ee=ASJRFf:DAnQ7e;Al0B8:kibjWe;DaIJ8c:iAskyc;EVNhjf:pw70Gc;EkYFhd:GwYlN;EmZ2Bf:zr1jrb;JsbNhc:Xd8iUd;K5nYTd:ZDZcre;LBgRLc:XVMNvd;Me32dd:MEeYgc;NPKaK:PVlQOd;NSEoX:lazG7b;Pjplud:EEDORb;QGR0gd:Mlhmy;SMDL4c:K0PMbc;SNUn3:ZwDk9d;ScI3Yc:e7Hzgb;UpnZUd:nnwwYc;Uvc8o:VDovNc;XdiAjb:NLiXbe;YIZmRd:A1yn5d;a56pNe:JEfCwb;cEt90b:ws9Tlc;dIoSBb:SpsfSb;dowIGb:ebZ3mb;eBAeSb:zbML3c;iFQyKf:vfuNJf;lOO0Vd:OTA3Ae;nAFL3:NTMZac;nTuGK:JKNPM;oGtAuc:sOXFj;oSUNyd:K0PMbc;oXZmbc:tUnxGc;pXdRYb:L9OGUe;qafBPd:yDVVkb;qddgKe:xQtZb;vNjB7d:YTxL4;wR5FRb:siKnQd;yxTchf:KUM7Z/m=byfTOb,lsjVmc,LEikZe:75:440)\n at Nfa (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:240:247)\n at Ik (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:237:47)\n at Object.Ob (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:236:471)\n at Nfa (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:240:247)\n at Ik (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:237:47)\n at _.Tf.aa (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:237:216)\n at Nfa (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:240:247)\n at Ik (https://www.gstatic.com/_/mss/boq-identity/_/js/k=boq-identity.OAuthUi.fr.TgEuxG-Yfgw.es5.O/am=YQBGxgZxWMxAOkMMIAAAAAAAAAAAGAAAYg/d=1/excm=_b,_tp,attributesview/ed=1/dg=0/wt=2/ujg=1/rs=AOaEmlFyVMi6I72cDllvT0N330NzLwGBug/m=_b,_tp:237:47)" [[Prototype]] : Error constructor : ƒ (a,b,c,d,e) getError : ƒ () [[Prototype]] : Error ``` Do you have any clue where it could come from? With my other Youtube account (on the same mail), I don't have any issue.
GiteaMirror added the locked label 2026-04-13 04:29:24 -05:00
Author
Owner

@Et3rnel commented on GitHub (Apr 15, 2025):

For some reasons, adding accessType: "offline" fixed the issue for the accounts that could be connected before.
I have no idea where it's coming from.

<!-- gh-comment-id:2807738691 --> @Et3rnel commented on GitHub (Apr 15, 2025): For some reasons, adding `accessType: "offline"` fixed the issue for the accounts that could be connected before. I have no idea where it's coming from.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9137