[GH-ISSUE #350] bug: Trusted Origins Configuration using Hono #8231

Closed
opened 2026-04-13 03:19:37 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @rokitgg on GitHub (Oct 27, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/350

I encountered this issue while working on a monorepo with a Hono server running @ localhost:8000, where the auth endpoints live, and a NextJS application running at localhost:3000.

For the specific use case, the NextJS frontend will communicate with the auth service which is hosted in another URL, so both apps need to "trust" each other.

The issue may come from the trustedOrigins config, which seems to not be applying correctly.

better-auth instance:

import { db } from '@repo/db';
import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';

export const auth = betterAuth({
	appName: 'better-auth-drizzle',
	baseUrl: 'http://localhost:8000/api/auth',
	database: drizzleAdapter(db, { provider: 'pg' }),
	trustedOrigins: ['http://localhost:3000'],
	rateLimit: {
		enabled: true,
	},
	logger: {
		disabled: false,
	},
// skipped plugins....

});

routes/auth.ts (Hono Request Handler)

import { auth as betterAuth } from '@repo/auth/server';
import type { Hono } from 'hono';
import type { AppVariables } from '../types';

export const auth = (app: Hono<AppVariables>) => {
	// if i console.log(betterAuth) here, trustedOrigins is defined as expected but not applied correctly.
	app.on(['POST', 'GET'], '/api/auth/*', (c) => {
		return betterAuth.handler(c.req.raw);
	});
};

better-auth error


Invalid callbackURL { callbackURL: 'http://localhost:3000', trustedOrigins: [ 'http://localhost:8000' ] }

The unexpected behavior comes from the logger reporting a trustedOrigins config that doesn't match the one previously specified in my instance.

Screenshots
image

Additional context

"better-auth": "0.6.0",
"hono": "^4.6.6",
"@hono/node-server": "^1.13.2"
Originally created by @rokitgg on GitHub (Oct 27, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/350 I encountered this issue while working on a monorepo with a Hono server running @ localhost:8000, where the auth endpoints live, and a NextJS application running at localhost:3000. For the specific use case, the NextJS frontend will communicate with the auth service which is hosted in another URL, so both apps need to "trust" each other. The issue may come from the **trustedOrigins** config, which seems to not be applying correctly. ### better-auth instance: ``` import { db } from '@repo/db'; import { betterAuth } from 'better-auth'; import { drizzleAdapter } from 'better-auth/adapters/drizzle'; export const auth = betterAuth({ appName: 'better-auth-drizzle', baseUrl: 'http://localhost:8000/api/auth', database: drizzleAdapter(db, { provider: 'pg' }), trustedOrigins: ['http://localhost:3000'], rateLimit: { enabled: true, }, logger: { disabled: false, }, // skipped plugins.... }); ``` ### routes/auth.ts (Hono Request Handler) ``` import { auth as betterAuth } from '@repo/auth/server'; import type { Hono } from 'hono'; import type { AppVariables } from '../types'; export const auth = (app: Hono<AppVariables>) => { // if i console.log(betterAuth) here, trustedOrigins is defined as expected but not applied correctly. app.on(['POST', 'GET'], '/api/auth/*', (c) => { return betterAuth.handler(c.req.raw); }); }; ``` ### better-auth error ``` Invalid callbackURL { callbackURL: 'http://localhost:3000', trustedOrigins: [ 'http://localhost:8000' ] } ``` The unexpected behavior comes from the logger reporting a trustedOrigins config that doesn't match the one previously specified in my instance. **Screenshots** ![image](https://github.com/user-attachments/assets/33481a6b-dba4-475a-ac08-d1b8e2821358) **Additional context** ``` "better-auth": "0.6.0", "hono": "^4.6.6", "@hono/node-server": "^1.13.2" ```
GiteaMirror added the locked label 2026-04-13 03:19:37 -05:00
Author
Owner

@Bekacru commented on GitHub (Oct 27, 2024):

update to latest. this has been fixed.

<!-- gh-comment-id:2439844692 --> @Bekacru commented on GitHub (Oct 27, 2024): update to latest. this has been fixed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8231