[GH-ISSUE #2753] Issue with genericOAuth - "Provider sync-ai is not supported" when fetching access token #26658

Closed
opened 2026-04-17 17:18:28 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @sajanv88 on GitHub (May 22, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2753

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Hey everyone,

I'm implementing the genericOAuth flow as described in the docs, and while the login flow works successfully, I'm running into an issue when trying to fetch the access token on the Next.js server side.

When calling auth.api.getAccessToken, I get the following error:

Here's a simplified snippet of my setup:

  const tokenSet = await auth.api.getAccessToken({
        body: { providerId: 'sync-ai', accountId }, headers: allHeaders
    });

auth.ts

export const providerId = "sync-ai"

export const auth = betterAuth({
    database: mongodbAdapter(db),

    plugins: [
        genericOAuth({
            config: [{
                providerId: providerId,
                clientId: 'syncai-ui',
                clientSecret: '', // this can be empty because this is a public client 
                discoveryUrl: `${process.env.AUTHORITY_URL}/.well-known/openid-configuration`,
                pkce: true,
                responseType: 'code',
                authentication: 'post',
                scopes: ['address', 'email', 'phone', 'profile', 'roles', 'AI'],
            }]
        })
    ]
});

Has anyone encountered this issue before?
Is there something I'm missing to ensure the provider is properly registered for getAccessToken?

Thanks in advance.

Current vs. Expected behavior

Current:
Provider sync-ai is not supported

Expected behavior:
When invoking getAccessToken it should return the token set

 {
    accessToken: string | undefined
    accessTokenExpiresAt: Date | undefined
    scopes: string[]
    idToken: string | undefined
 }

What version of Better Auth are you using?

1.2.8

Provide environment information

- OS: [Popos Linux]
- Browser: Brave

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

Backend, Client, Documentation, Package, Other


### Additional context

_No response_
Originally created by @sajanv88 on GitHub (May 22, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2753 ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce Hey everyone, I'm implementing the genericOAuth flow as described in the docs, and while the login flow works successfully, I'm running into an issue when trying to fetch the access token on the Next.js server side. When calling `auth.api.getAccessToken`, I get the following error: Here's a simplified snippet of my setup: ```ts const tokenSet = await auth.api.getAccessToken({ body: { providerId: 'sync-ai', accountId }, headers: allHeaders }); ``` `auth.ts` ```ts export const providerId = "sync-ai" export const auth = betterAuth({ database: mongodbAdapter(db), plugins: [ genericOAuth({ config: [{ providerId: providerId, clientId: 'syncai-ui', clientSecret: '', // this can be empty because this is a public client discoveryUrl: `${process.env.AUTHORITY_URL}/.well-known/openid-configuration`, pkce: true, responseType: 'code', authentication: 'post', scopes: ['address', 'email', 'phone', 'profile', 'roles', 'AI'], }] }) ] }); ``` Has anyone encountered this issue before? Is there something I'm missing to ensure the provider is properly registered for `getAccessToken`? Thanks in advance. ### Current vs. Expected behavior **Current:** Provider sync-ai is not supported **Expected behavior:** When invoking `getAccessToken` it should return the token set ``` { accessToken: string | undefined accessTokenExpiresAt: Date | undefined scopes: string[] idToken: string | undefined } ``` ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash - OS: [Popos Linux] - Browser: Brave ``` ### Which area(s) are affected? (Select all that apply) Backend, Client, Documentation, Package, Other ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-17 17:18:28 -05:00
Author
Owner

@sajanv88 commented on GitHub (May 23, 2025):

@Bekacru Thanks for looking into issue #2753!

I have tested your update with better-auth@2754, and I can confirm that the original error from #2753 is now resolved great work!

However, it seems this change may have introduced a new issue: When getAccessToken called.

[
  {
    id: '683006f92cf517e5489bf7bc',
    provider: 'sync-ai',
    createdAt: 2025-05-23T05:26:17.064Z,
    updatedAt: 2025-05-23T05:26:17.064Z,
    accountId: '0376850d-ca5e-af04-61eb-3a1a03dbfbc3',
    scopes: [ 'address', 'email', 'phone', 'profile', 'roles', 'AI' ]
  }
] 

error


accountId => 0376850d-ca5e-af04-61eb-3a1a03dbfbc3 

 ⨯ [Error [APIError]: Account not found] {
  status: 'BAD_REQUEST',
  body: [Object],
  headers: {},
  statusCode: 400,
  digest: '1779519783'
}
<!-- gh-comment-id:2903316687 --> @sajanv88 commented on GitHub (May 23, 2025): @Bekacru Thanks for looking into issue #2753! I have tested your update with `better-auth@2754`, and I can confirm that the original error from #2753 is now resolved great work! However, it seems this change may have introduced a new issue: When `getAccessToken` called. ```js [ { id: '683006f92cf517e5489bf7bc', provider: 'sync-ai', createdAt: 2025-05-23T05:26:17.064Z, updatedAt: 2025-05-23T05:26:17.064Z, accountId: '0376850d-ca5e-af04-61eb-3a1a03dbfbc3', scopes: [ 'address', 'email', 'phone', 'profile', 'roles', 'AI' ] } ] ``` error ```bash accountId => 0376850d-ca5e-af04-61eb-3a1a03dbfbc3 ⨯ [Error [APIError]: Account not found] { status: 'BAD_REQUEST', body: [Object], headers: {}, statusCode: 400, digest: '1779519783' } ```
Author
Owner

@hash817 commented on GitHub (Jun 4, 2025):

Facing same issue, did you ever get this fixed? @sajanv88

<!-- gh-comment-id:2939600382 --> @hash817 commented on GitHub (Jun 4, 2025): Facing same issue, did you ever get this fixed? @sajanv88
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#26658