[GH-ISSUE #202] Error using a different base path for socialProviders #25493

Closed
opened 2026-04-17 15:44:41 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @benquan on GitHub (Oct 16, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/202

Describe the bug
I am trying to use a different path for social providers. For what I understand, the default basePath is /api/auth. I am trying to remove the /api portion and just use /auth.

To Reproduce
I am using sveltekit. And my understanding is that using this auth definition would generate an automatic callback for google at /auth/callback/google

export const auth = betterAuth({
	basePath: '/auth',
	database: drizzleAdapter(db, {
		provider: 'sqlite' // or "mysql", "sqlite"
	}),
	emailAndPassword: {
		enabled: true
	},
	socialProviders: {
		google: {
			redirectURI: 'http://localhost:5173/auth/callback/google',
			scope: ['profile', 'email'],
			clientId: process.env.GOOGLE_ID as string,
			clientSecret: process.env.GOOGLE_SECRET as string
		}
	}
});

I am calling it with:

<button
	on:click={async () => {
		await authClient.signIn.social({
			provider: 'google'
		});
	}}
>
	Continue with Google
</button>

Expected behavior
I would expect for the google auth process to run and after the callback, control would return to the root or some defined final destination.

What I am getting is google trying to go to the defined callback http://localhost:5173/auth/callback/google but not finding anything there (404). I would think that by placing basePath: '/auth', would be enough to use that path instead of the default /api/auth

Screenshot 2024-10-16 at 4 27 20 PM
Originally created by @benquan on GitHub (Oct 16, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/202 **Describe the bug** I am trying to use a different path for social providers. For what I understand, the default basePath is **/api/auth**. I am trying to remove the /api portion and just use **/auth**. **To Reproduce** I am using sveltekit. And my understanding is that using this auth definition would generate an automatic callback for google at /auth/callback/google ``` export const auth = betterAuth({ basePath: '/auth', database: drizzleAdapter(db, { provider: 'sqlite' // or "mysql", "sqlite" }), emailAndPassword: { enabled: true }, socialProviders: { google: { redirectURI: 'http://localhost:5173/auth/callback/google', scope: ['profile', 'email'], clientId: process.env.GOOGLE_ID as string, clientSecret: process.env.GOOGLE_SECRET as string } } }); ``` I am calling it with: ``` <button on:click={async () => { await authClient.signIn.social({ provider: 'google' }); }} > Continue with Google </button> ``` **Expected behavior** I would expect for the google auth process to run and after the callback, control would return to the root or some defined final destination. What I am getting is google trying to go to the defined callback **http://localhost:5173/auth/callback/google** but not finding anything there (404). I would think that by placing **basePath: '/auth',** would be enough to use that path instead of the default /api/auth <img width="610" alt="Screenshot 2024-10-16 at 4 27 20 PM" src="https://github.com/user-attachments/assets/034d55f5-6918-4155-97a1-01ecd88e0ebc">
GiteaMirror added the locked label 2026-04-17 15:44:41 -05:00
Author
Owner

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

are you sure you have mounted the handler on the correct base path?

<!-- gh-comment-id:2418517506 --> @Bekacru commented on GitHub (Oct 17, 2024): are you sure you have mounted the handler on the correct base path?
Author
Owner

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

feel free to re-open if this isn't fixed.

<!-- gh-comment-id:2423750451 --> @Bekacru commented on GitHub (Oct 19, 2024): feel free to re-open if this isn't fixed.
Author
Owner

@emersonlaurentino commented on GitHub (Dec 7, 2024):

@Bekacru I've the same issue, but the problem is on the client, because I can set the basePath on the server, but when I call signIn.social({ provider: "google" }) for example, the basePath is the default and I can't set it on the createAuthClient

<!-- gh-comment-id:2524834979 --> @emersonlaurentino commented on GitHub (Dec 7, 2024): @Bekacru I've the same issue, but the problem is on the client, because I can set the `basePath` on the server, but when I call `signIn.social({ provider: "google" })` for example, the basePath is the default and I can't set it on the `createAuthClient`
Author
Owner

@amosbastian commented on GitHub (Feb 16, 2025):

@Bekacru I've the same issue, but the problem is on the client, because I can set the basePath on the server, but when I call signIn.social({ provider: "google" }) for example, the basePath is the default and I can't set it on the createAuthClient

I have the same problem, not sure how to make the client aware of the new path 🤔

<!-- gh-comment-id:2661588904 --> @amosbastian commented on GitHub (Feb 16, 2025): > [@Bekacru](https://github.com/Bekacru) I've the same issue, but the problem is on the client, because I can set the `basePath` on the server, but when I call `signIn.social({ provider: "google" })` for example, the basePath is the default and I can't set it on the `createAuthClient` I have the same problem, not sure how to make the client aware of the new path 🤔
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#25493