Request: Better logging on generic OAuth flow #578

Open
opened 2026-03-13 07:54:22 -05:00 by GiteaMirror · 7 comments
Owner

Originally created by @zhawtof on GitHub (Jan 21, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

My issue is I am receiving an empty tokens list from Slack (a generic OAuth setup). Everything is giving me a 200 response, and there are no errors, which leads me to believe that there is a misconfiguration on my end or better-auth is hiding an error.

My current setup:

  • Frontend: NextJS
  • Backend: Hono on Cloudflare

My auth config is below but because Cloudflare does not support process.env this is my working setup:

auth.ts on Backend

import { betterAuth } from 'better-auth';
import { genericOAuth } from 'better-auth/plugins';
import { Pool } from 'pg';

export function createAuth(env: CloudflareEnv) {
  const pool = new Pool({
    connectionString: env.DATABASE_URL!
  });
  return betterAuth({
    database: pool,
    secret: env.BETTER_AUTH_SECRET!,
    plugins: [
      genericOAuth({
        config: [
          {
            providerId: 'slack',
            clientId: env.SLACK_CLIENT_ID!,
            clientSecret: env.SLACK_CLIENT_SECRET!,
            discoveryUrl: 'https://slack.com/.well-known/openid-configuration',
            scopes: ['openid', 'profile', 'email'],
            redirectURI:
              '<my-local-url>/api/auth/oauth2/callback/slack',
            // using to log the tokens response which is pictured below
            getUserInfo: async (tokens) => {
              console.log('tokens', tokens);
              return {
                id: '123',
                email: 'test@test.com',
                name: 'Test User',
                emailVerified: true,
                createdAt: new Date(),
                updatedAt: new Date()
              };
            }
          }
        ]
      })
    ]
  });
}

/**
 * This is only used for the migration script
 * npx @better-auth/cli migrate
 */
export const auth = betterAuth({
  database: new Pool({
    connectionString: process.env.DATABASE_URL!
  })
});

Current vs. Expected behavior

Actual:
Image

Expected:
Successful token response or, at a minimum, more errors and more logging on why this failed.

What version of Better Auth are you using?

1.1.14

Provide environment information

- OS: MacOS 15.2
- Browser: Chrome 131.0.6778.265

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

Backend

Auth config (if applicable)

betterAuth({
    database: pool,
    secret: env.BETTER_AUTH_SECRET!,
    plugins: [
      genericOAuth({
        config: [
          {
            providerId: 'slack',
            clientId: env.SLACK_CLIENT_ID!,
            clientSecret: env.SLACK_CLIENT_SECRET!,
            discoveryUrl: 'https://slack.com/.well-known/openid-configuration',
            scopes: ['openid', 'profile', 'email'],
            redirectURI:
              '<my-local-url>/api/auth/oauth2/callback/slack',
            
            getUserInfo: async (tokens) => {
              console.log('tokens', tokens);
              return {
                id: '123',
                email: 'test@test.com',
                name: 'Test User',
                emailVerified: true,
                createdAt: new Date(),
                updatedAt: new Date()
              };
            }
          }
        ]
      })
    ]

Additional context

This is my first time moving to BetterAuth. Currently migrating off of Supabase Auth because they do not support custom Social Logins, which is a requirement from our customers.

However, have had a really rough patch in understanding Better Auth. It seems like a great framework when things "just work" but the debuggability is very low. It would be nice to have a verbose option for debugging this since I can barely tell what's happening once information goes into the system.

Originally created by @zhawtof on GitHub (Jan 21, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce My issue is I am receiving an empty tokens list from Slack (a generic OAuth setup). Everything is giving me a 200 response, and there are no errors, which leads me to believe that there is a misconfiguration on my end or better-auth is hiding an error. My current setup: - Frontend: NextJS - Backend: Hono on Cloudflare My auth config is below but because Cloudflare does not support `process.env` this is my working setup: `auth.ts` on Backend ```ts import { betterAuth } from 'better-auth'; import { genericOAuth } from 'better-auth/plugins'; import { Pool } from 'pg'; export function createAuth(env: CloudflareEnv) { const pool = new Pool({ connectionString: env.DATABASE_URL! }); return betterAuth({ database: pool, secret: env.BETTER_AUTH_SECRET!, plugins: [ genericOAuth({ config: [ { providerId: 'slack', clientId: env.SLACK_CLIENT_ID!, clientSecret: env.SLACK_CLIENT_SECRET!, discoveryUrl: 'https://slack.com/.well-known/openid-configuration', scopes: ['openid', 'profile', 'email'], redirectURI: '<my-local-url>/api/auth/oauth2/callback/slack', // using to log the tokens response which is pictured below getUserInfo: async (tokens) => { console.log('tokens', tokens); return { id: '123', email: 'test@test.com', name: 'Test User', emailVerified: true, createdAt: new Date(), updatedAt: new Date() }; } } ] }) ] }); } /** * This is only used for the migration script * npx @better-auth/cli migrate */ export const auth = betterAuth({ database: new Pool({ connectionString: process.env.DATABASE_URL! }) }); ``` ### Current vs. Expected behavior Actual: <img width="307" alt="Image" src="https://github.com/user-attachments/assets/7086dc63-3c3f-4b64-898d-bb1e99a82320" /> Expected: Successful token response or, at a minimum, more errors and more logging on why this failed. ### What version of Better Auth are you using? 1.1.14 ### Provide environment information ```bash - OS: MacOS 15.2 - Browser: Chrome 131.0.6778.265 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript betterAuth({ database: pool, secret: env.BETTER_AUTH_SECRET!, plugins: [ genericOAuth({ config: [ { providerId: 'slack', clientId: env.SLACK_CLIENT_ID!, clientSecret: env.SLACK_CLIENT_SECRET!, discoveryUrl: 'https://slack.com/.well-known/openid-configuration', scopes: ['openid', 'profile', 'email'], redirectURI: '<my-local-url>/api/auth/oauth2/callback/slack', getUserInfo: async (tokens) => { console.log('tokens', tokens); return { id: '123', email: 'test@test.com', name: 'Test User', emailVerified: true, createdAt: new Date(), updatedAt: new Date() }; } } ] }) ] ``` ### Additional context This is my first time moving to BetterAuth. Currently migrating off of Supabase Auth because they do not support custom Social Logins, which is a requirement from our customers. However, have had a really rough patch in understanding Better Auth. It seems like a great framework when things "just work" but the debuggability is very low. It would be nice to have a `verbose` option for debugging this since I can barely tell what's happening once information goes into the system.
GiteaMirror added the bug label 2026-03-13 07:54:22 -05:00
Author
Owner

@benjamindell commented on GitHub (Jan 26, 2025):

I'm also having the same issue. Im trying to create a generic oauth connection for Stripe. It seems to go through the Stripe auth flow as expected but then sends back to my server and better auth returns a really vague error. Its incredibly difficult to know where to start debugging.

@benjamindell commented on GitHub (Jan 26, 2025): I'm also having the same issue. Im trying to create a generic oauth connection for Stripe. It seems to go through the Stripe auth flow as expected but then sends back to my server and better auth returns a really vague error. Its incredibly difficult to know where to start debugging.
Author
Owner

@ducheharsh commented on GitHub (May 3, 2025):

hey @zhawtof how do you handle the redirect uri, because whenever i try to use google oauth it redirects me to the backend server, i tried the cross domain thing suggested in docs but it does not work

@ducheharsh commented on GitHub (May 3, 2025): hey @zhawtof how do you handle the redirect uri, because whenever i try to use google oauth it redirects me to the backend server, i tried the cross domain thing suggested in docs but it does not work
Author
Owner

@vnenkpet commented on GitHub (Jun 19, 2025):

I second this. Currently trying to implement the generic oauth but it's incredibly hard to know what is happening. I am literally just getting "Invalid OAuth configuration" which is not much to go by.

@vnenkpet commented on GitHub (Jun 19, 2025): I second this. Currently trying to implement the generic oauth but it's incredibly hard to know what is happening. I am literally just getting "Invalid OAuth configuration" which is not much to go by.
Author
Owner

@eden-lane commented on GitHub (Jul 21, 2025):

It took some time to understand what better-auth wants from me with the "Invalid OAuth configuration" error. According to the code, one of the possible reasons was the missing finalAuthUrl. My provider was Google (I had to do it via a plugin because I needed to define it twice, while the socialProviders config doesn't allow this), so I found a discoveryUrl for Google Auth (which is https://accounts.google.com/.well-known/openid-configuration) and passed it to the config, and the error was fixed.

My final config is:

config: [
  {
    providerId: 'google-web',
    discoveryUrl: 'https://accounts.google.com/.well-known/openid-configuration',
    clientId: process.env.GOOGLE_CLIENT_ID as string,
    clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
    redirectURI: process.env.GOOGLE_REDIRECT_URI as string,
    accessType: 'offline',
    scopes: [
      'https://www.googleapis.com/auth/userinfo.profile',
      'https://www.googleapis.com/auth/userinfo.email',
      'https://www.googleapis.com/auth/calendar',
      'https://www.googleapis.com/auth/calendar.events',
      'https://www.googleapis.com/auth/contacts.readonly',
      'https://www.googleapis.com/auth/contacts.other.readonly',
    ],
  }
]
@eden-lane commented on GitHub (Jul 21, 2025): It took some time to understand what better-auth wants from me with the "Invalid OAuth configuration" error. According to the code, one of the possible reasons was the missing `finalAuthUrl`. My provider was Google (I had to do it via a plugin because I needed to define it twice, while the `socialProviders` config doesn't allow this), so I found a discoveryUrl for Google Auth (which is https://accounts.google.com/.well-known/openid-configuration) and passed it to the config, and the error was fixed. My final config is: ```js config: [ { providerId: 'google-web', discoveryUrl: 'https://accounts.google.com/.well-known/openid-configuration', clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, redirectURI: process.env.GOOGLE_REDIRECT_URI as string, accessType: 'offline', scopes: [ 'https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.events', 'https://www.googleapis.com/auth/contacts.readonly', 'https://www.googleapis.com/auth/contacts.other.readonly', ], } ] ```
Author
Owner

@adryd325 commented on GitHub (Oct 15, 2025):

+1 on this. I should not be having to set breakpoints in library code to figure out whats going wrong

If the betterauth logger is set to debug it should really log if any http requests to the backend have errors.

@adryd325 commented on GitHub (Oct 15, 2025): +1 on this. I should not be having to set breakpoints in library code to figure out whats going wrong If the betterauth logger is set to debug it should really log if any http requests to the backend have errors.
Author
Owner

@dosubot[bot] commented on GitHub (Jan 14, 2026):

Hi, @zhawtof. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that using better-auth's generic OAuth setup with Slack returns an empty tokens list despite successful 200 responses, suspecting hidden errors or misconfiguration.
  • Other users confirmed similar issues with vague "Invalid OAuth configuration" errors when integrating providers like Stripe and Google.
  • A workaround involving specifying Google's discoveryUrl was shared to fix the error for Google.
  • There is a recognized need for improved debug logging in the library to help troubleshoot these OAuth integration issues more effectively.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open.
  • If I do not hear back within 7 days, I will automatically close this issue.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jan 14, 2026): Hi, @zhawtof. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that using better-auth's generic OAuth setup with Slack returns an empty tokens list despite successful 200 responses, suspecting hidden errors or misconfiguration. - Other users confirmed similar issues with vague "Invalid OAuth configuration" errors when integrating providers like Stripe and Google. - A workaround involving specifying Google's discoveryUrl was shared to fix the error for Google. - There is a recognized need for improved debug logging in the library to help troubleshoot these OAuth integration issues more effectively. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open. - If I do not hear back within 7 days, I will automatically close this issue. Thank you for your understanding and contribution!
Author
Owner

@adryd325 commented on GitHub (Jan 14, 2026):

@dosubot The issue is still relevant. (I think it only listens to OP but one can try)

@adryd325 commented on GitHub (Jan 14, 2026): @dosubot The issue is still relevant. (I think it only listens to OP but one can try)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#578