[GH-ISSUE #3169] is better-auth has debug mode like next-auth #26823

Closed
opened 2026-04-17 17:32:17 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @sionnx on GitHub (Jun 25, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3169

Is this suited for github?

  • Yes, this is suited for github

better auth is very difficult to debug now, it would be easier if there was a debug mode, like this one for next auth: https://authjs.dev/guides/debugging

Describe the solution you'd like

The current better auth is already great, a debug mode would be great!

Describe alternatives you've considered

I tried wrapping toNextJsHandler to get the request url, but it's still hard to solve when there's unintended behavior, and at this point better auth is more of a black box

import { auth } from "@/lib/auth/server";
import { toNextJsHandler } from "better-auth/next-js";

const originalHandler = toNextJsHandler(auth.handler);

export const GET = async (req: Request) => {
  console.log(`Auth Request URL: ${req.url}`);
  return originalHandler.GET(req);
};

export const POST = async (req: Request) => {
  console.log(`Auth Request URL: ${req.url}`);
  return originalHandler.POST(req);
};

Additional context

No response

Originally created by @sionnx on GitHub (Jun 25, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3169 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. better auth is very difficult to debug now, it would be easier if there was a debug mode, like this one for next auth: https://authjs.dev/guides/debugging ### Describe the solution you'd like The current better auth is already great, a debug mode would be great! ### Describe alternatives you've considered I tried wrapping toNextJsHandler to get the request url, but it's still hard to solve when there's unintended behavior, and at this point better auth is more of a black box ``` import { auth } from "@/lib/auth/server"; import { toNextJsHandler } from "better-auth/next-js"; const originalHandler = toNextJsHandler(auth.handler); export const GET = async (req: Request) => { console.log(`Auth Request URL: ${req.url}`); return originalHandler.GET(req); }; export const POST = async (req: Request) => { console.log(`Auth Request URL: ${req.url}`); return originalHandler.POST(req); }; ``` ### Additional context _No response_
GiteaMirror added the lockedenhancement labels 2026-04-17 17:32:17 -05:00
Author
Owner

@Kinfe123 commented on GitHub (Jun 25, 2025):

check this changes on #3171 with in the docs. this should help you out.

<!-- gh-comment-id:3005891256 --> @Kinfe123 commented on GitHub (Jun 25, 2025): check this changes on #3171 with in the docs. this should help you out.
Author
Owner

@sionnx commented on GitHub (Jun 26, 2025):

check this changes on #3171 with in the docs. this should help you out.

Thank you very much for your answer, I referred to this document and turned on the debug logger, but nothing happens, is this normal?

I am using apple to log in, configured correctly and can authenticate successfully, here is my current situation:

better-auth:1.2.10
Next.js : 15.3.4

server side auth code:

export const auth = betterAuth({
  //basePath: "/api/auth",
  secret: process.env.AUTH_SECRET,
  trustedOrigins: [process.env.NEXT_PUBLIC_APP_URL!],
  plugins: [openAPI()],
  database: authAdapter(db, {
    provider: "pg",
    schema: authSchema,
   // debugLogs: true,
  }),
  socialProviders: {
    apple: {
      clientId: process.env.AUTH_APPLE_ID!,
      clientSecret: process.env.AUTH_APPLE_SECRET!,
    },
  },
  logger: {
    disabled: false,
    level: "debug", //error,warn,info,debug
    log: (level, message, ...args) => {
      // Custom logging implementation
      console.log(`[BetterAuth][${level}] ${message}`, ...args);
    },
  },
});

log in terminal, no debugging information output:

yarn run v1.22.22
$ next dev --turbopack --port 3000
   ▲ Next.js 15.3.4 (Turbopack)
   - Local:        http://localhost:3000
   - Network:      http://192.168.0.104:3000
   - Environments: .env.local, .env

 ✓ Starting...
 ✓ Ready in 758ms
 ○ Compiling / ...
 GET / 200 in 1844ms
 ✓ Compiled / in 1851ms
 GET /auth 200 in 619ms
 ○ Compiling /api/auth/[...auth] ...
 ✓ Compiled /api/auth/[...auth] in 811ms
 POST /api/auth/sign-in/social 200 in 3477ms
 POST /api/auth/callback/apple 302 in 2814ms
 GET / 200 in 189ms
<!-- gh-comment-id:3007273824 --> @sionnx commented on GitHub (Jun 26, 2025): > check this changes on [#3171](https://github.com/better-auth/better-auth/pull/3171) with in the docs. this should help you out. Thank you very much for your answer, I referred to this document and turned on the debug logger, but nothing happens, is this normal? I am using apple to log in, configured correctly and can authenticate successfully, here is my current situation: better-auth:1.2.10 Next.js : 15.3.4 server side auth code: ```typescript export const auth = betterAuth({ //basePath: "/api/auth", secret: process.env.AUTH_SECRET, trustedOrigins: [process.env.NEXT_PUBLIC_APP_URL!], plugins: [openAPI()], database: authAdapter(db, { provider: "pg", schema: authSchema, // debugLogs: true, }), socialProviders: { apple: { clientId: process.env.AUTH_APPLE_ID!, clientSecret: process.env.AUTH_APPLE_SECRET!, }, }, logger: { disabled: false, level: "debug", //error,warn,info,debug log: (level, message, ...args) => { // Custom logging implementation console.log(`[BetterAuth][${level}] ${message}`, ...args); }, }, }); ``` log in terminal, no debugging information output: ```text yarn run v1.22.22 $ next dev --turbopack --port 3000 ▲ Next.js 15.3.4 (Turbopack) - Local: http://localhost:3000 - Network: http://192.168.0.104:3000 - Environments: .env.local, .env ✓ Starting... ✓ Ready in 758ms ○ Compiling / ... GET / 200 in 1844ms ✓ Compiled / in 1851ms GET /auth 200 in 619ms ○ Compiling /api/auth/[...auth] ... ✓ Compiled /api/auth/[...auth] in 811ms POST /api/auth/sign-in/social 200 in 3477ms POST /api/auth/callback/apple 302 in 2814ms GET / 200 in 189ms ```
Author
Owner

@patrickgdl commented on GitHub (Jun 29, 2025):

Having the same as @angus-cx, apparently enabled but no log showing:

betterAuth({
    database: drizzleAdapter(db, { provider: "sqlite" }),
    secret: env.BETTER_AUTH_SECRET,
    socialProviders: {
      google: {
        prompt: "select_account",
        clientId: env.GOOGLE_CLIENT_ID,
        clientSecret: env.GOOGLE_CLIENT_SECRET,
      },
    },
    logger: {
      disabled: false,
      level: "info",
      log: (level, message, ...args) => {
        // Custom logging implementation
        console.log(`Better auth [${level}] ${message}`, ...args);
      }
    },
    plugins: [openAPI(), organization()],
    databaseHooks: {
      session: {
        create: {
          before: async (session) => {
            const organization = await getActiveOrganization(session.userId, db)

            if (!organization) {
              return {
                data: {
                  ...session,
                  activeOrganizationId: null
                }
              }
            }

            return {
              data: {
                ...session,
                activeOrganizationId: organization.id
              }
            }
          }
        }
      }
    },
  })
<!-- gh-comment-id:3016760546 --> @patrickgdl commented on GitHub (Jun 29, 2025): Having the same as @angus-cx, apparently enabled but no log showing: ``` betterAuth({ database: drizzleAdapter(db, { provider: "sqlite" }), secret: env.BETTER_AUTH_SECRET, socialProviders: { google: { prompt: "select_account", clientId: env.GOOGLE_CLIENT_ID, clientSecret: env.GOOGLE_CLIENT_SECRET, }, }, logger: { disabled: false, level: "info", log: (level, message, ...args) => { // Custom logging implementation console.log(`Better auth [${level}] ${message}`, ...args); } }, plugins: [openAPI(), organization()], databaseHooks: { session: { create: { before: async (session) => { const organization = await getActiveOrganization(session.userId, db) if (!organization) { return { data: { ...session, activeOrganizationId: null } } } return { data: { ...session, activeOrganizationId: organization.id } } } } } }, }) ```
Author
Owner

@ping-maxwell commented on GitHub (Jul 1, 2025):

Hey guys, this is normal. Unfortunately there isn't much debug logs built into some of these endpoints, so even after enabling those debug log options nothing would appear.

<!-- gh-comment-id:3021292951 --> @ping-maxwell commented on GitHub (Jul 1, 2025): Hey guys, this is normal. Unfortunately there isn't much debug logs built into some of these endpoints, so even after enabling those debug log options nothing would appear.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#26823