baseUrl not being respected #1295

Closed
opened 2026-03-13 08:31:44 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @Nickersoft on GitHub (Jun 2, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

I'm currently using the Svelte integration for better-auth and have noticed it isn't respecting the baseUrl I am setting. Specifically, I'm trying to write a Tauri app and regardless of my baseUrl, calling getSession() dispatches a request to tauri://localhost/get-session:

  1. Setup better-auth with the Svelte integration
  2. Set a base URL
  3. Call getSession()
  4. Check your network requests

Current vs. Expected behavior

Unless I'm mistaken, I would expect all better-auth requests to be ${baseUrl}/${requested route}. Not sure why it seems to just be using absolute ('/') paths.

What version of Better Auth are you using?

1.2.8

Provide environment information

- macOS Sequoia 15.5
- Tauri WRY

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

Client

Auth config (if applicable)

import { v4 as uuid } from 'uuid';

import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { jwt } from 'better-auth/plugins';

import { GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET } from '$env/static/private';

import { db } from '../db/database';

import * as schema from '../db/schema';

import { dev } from '$app/environment';

const trustedOrigins = ['https://www.mydomain.com', 'https://mydomain.com', 'my-app://auth/google'];

if (dev) {
	trustedOrigins.push('http://localhost:5173');
}

export const auth = betterAuth({
	plugins: [jwt()],
	trustedOrigins,
	advanced: {
		database: {
			generateId: () => uuid()
		}
	},
	socialProviders: {
		google: {
			clientId: GOOGLE_CLIENT_ID,
			clientSecret: GOOGLE_CLIENT_SECRET,
			mapProfileToUser: ({ given_name: firstName, family_name: lastName }) => ({
				firstName,
				lastName
			})
		}
	},
	database: drizzleAdapter(db, {
		usePlural: true,
		provider: 'pg',
		schema
	})
});

Additional context

Interestingly enough, setting baseUrl on my auth instance (not the client) causes my client requests to fail, despite being sent to the same URL.

Originally created by @Nickersoft on GitHub (Jun 2, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce I'm currently using the Svelte integration for better-auth and have noticed it isn't respecting the `baseUrl` I am setting. Specifically, I'm trying to write a Tauri app and regardless of my `baseUrl`, calling `getSession()` dispatches a request to `tauri://localhost/get-session`: 1. Setup better-auth with the Svelte integration 2. Set a base URL 3. Call `getSession()` 4. Check your network requests ### Current vs. Expected behavior Unless I'm mistaken, I would expect all better-auth requests to be `${baseUrl}/${requested route}`. Not sure why it seems to just be using absolute ('/') paths. ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash - macOS Sequoia 15.5 - Tauri WRY ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import { v4 as uuid } from 'uuid'; import { betterAuth } from 'better-auth'; import { drizzleAdapter } from 'better-auth/adapters/drizzle'; import { jwt } from 'better-auth/plugins'; import { GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET } from '$env/static/private'; import { db } from '../db/database'; import * as schema from '../db/schema'; import { dev } from '$app/environment'; const trustedOrigins = ['https://www.mydomain.com', 'https://mydomain.com', 'my-app://auth/google']; if (dev) { trustedOrigins.push('http://localhost:5173'); } export const auth = betterAuth({ plugins: [jwt()], trustedOrigins, advanced: { database: { generateId: () => uuid() } }, socialProviders: { google: { clientId: GOOGLE_CLIENT_ID, clientSecret: GOOGLE_CLIENT_SECRET, mapProfileToUser: ({ given_name: firstName, family_name: lastName }) => ({ firstName, lastName }) } }, database: drizzleAdapter(db, { usePlural: true, provider: 'pg', schema }) }); ``` ### Additional context Interestingly enough, setting `baseUrl` on my auth instance (not the client) causes my client requests to fail, despite being sent to the same URL.
Author
Owner

@Nickersoft commented on GitHub (Jun 2, 2025):

Jk I'm an idiot – it's baseURL, not baseUrl and VSCode never threw an error, so I assumed it correct. Fixing the case fixed it!

@Nickersoft commented on GitHub (Jun 2, 2025): Jk I'm an idiot – it's `baseURL`, not `baseUrl` and VSCode never threw an error, so I assumed it correct. Fixing the case fixed it!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1295