Better Auth

BA

Better Auth

Join the community to ask questions about Better Auth and get answers from other members.

Join

bug-reports

help

how to return more data from `/get-session`

hello, I would want to store user's balance inside session object, instead of fetching it manually I tried to create a plugin for better auth, but it doesn't work (it worked a few days before, I didn't change code nor updated dependencies...) ```ts import type { BetterAuthClientPlugin } from "better-auth/client";...

User Cancelling Authentication Redirects to Better Auth Error Page

```export const facebookSignIn = async () => { const data = await authClient.signIn.social({ provider: "facebook", callbackURL: "/profile", errorCallbackURL: "/sign-in",...
Solution:
ended up fixing this by adding errorURL to my betterAuth for the onAPIError property ``` onAPIError: { throw: true, onError: (error, ctx) => { console.error("Auth error:", error);...

Guidance on JWT / Bearer usage for external APIs

Hi all, after some tinkering, I have JWT set up within a Nextjs app to use as a bearer token for an external api. The api uses the JWKS endpoint to validate the token. This works fine. I am looking for guidance of best implementation guidelines for security and performance. We heavily use server patterns in Next so we don't rely on nor use authClient, just the server api. At the moment, if I call auth.api.getToken, it issues a new token every time thus invalidating any fetch caching to the external api. I can store this token outside the request scope (variable or local storage) however this doesn't take into account expiration of the JWT token within decrypt it and checking timestamps on each request. While this works, I am wondering if there's a more efficient or more "betterauth" way of doing this. Perhaps the OIDC Provider is a better choice here? To sum:...

Expo Sign in with Apple: clientId vs appId vs serviceId vs bundleId ?!? 🤷

Trying to work through this: https://www.better-auth.com/docs/authentication/apple#configure-the-provider It says:
On native iOS, it doesn't use the service id but the app id (bundle id) as client id, so if using the service id as clientId in signIn.social() with idToken, it throws an error: JWTClaimValidationFailed: unexpected "aud" claim value. So you need to provide the appBundleIdentifier when you want to sign in with Apple using the ID Token....
Solution:
I figured it out - the appBundleIdentifier has to be host.exp.Exponent when using expo dev

How to update `api/auth/get-session` with new session data?

I am updating the users table with the new name but accessing api/auth/get-session gives the old data. Is there a way to trigger an update when the database is updated so session data is also updated? I am using tanstack start. ```import { createAPIFileRoute } from '@tanstack/react-start/api' import { auth } from '@/lib/auth'...

Issue trying to convert to cloudflare workers

I have my project currently deployed on vercel as a NextJs project. I'm trying to convert it to cloudflare workers using opennextjs/cloudflare, however I'm encountering some issues with the auth handler. ``` /api/auth/get-session - Exception Thrown @ 4/5/2025, 9:35:09 PM ✘ [ERROR] Error: The script will never generate a response....

can Stripe's period_end be overwritten?

Stripe plugin and Sveltekit question. I am building an app where a free 7-day trial triggers on first log in using the better-auth stripe plugin. the period_start and period_end in the schema get correctly set on first login. When the user goes to Stripe.com to complete checkout, the period_start and period_end resets with a new timestamp so this could turn the 7-day free trial into a 14-day free trial if they complete the stripe checkout at the end of the first 7 days. I set trial_end to match...
Solution:
why not just only rely on trail_end for the trail period and if have have non-trail subscription, you'll start usnig period start and end as a flag instead.

subscription table is not generated

Following https://www.better-auth.com/docs/plugins/stripe#subscription guide and version 1.2.5 my auth looks like: ``` export const auth = betterAuth({...
No description

Stripe plugin

Using the Stripe plugin, I have the subscription configuration: subscription: { enabled: true, plans: [...

Check GitHub organisation

Hello, is it possible to check what GitHub organisation someone is in with the GitHub social provider and limit logins based on that? Thanks in advance <3
Solution:
betterauth just maps only a few fields from the whole github profile response. you wouldn't get such details.

Backup Verify

# SERVER_ERROR: Error: padded hex string expected, got unpadded hex of length 191
at hexToBytes (../src/utils.ts:56:20)
POST /api/auth/two-factor/verify-backup-code 500 in 165ms
# SERVER_ERROR: Error: padded hex string expected, got unpadded hex of length 191
at hexToBytes (../src/utils.ts:56:20)
POST /api/auth/two-factor/verify-backup-code 500 in 165ms
...
No description

OTP

Hello, im trying to verify if the OTP is correct from the AUTH application. But i have these errors when i try to verify the code ``` await authClient.twoFactor.verifyOtp({ code: code }, { onSuccess() { console.log("OTP verification successful");...
Solution:
Im just stupid and used OTP instead of TOTP
No description

Long delay after logging in with Apple (white screen)

It works but it causes quite a delay. What can I do to fix this? auth.ts ```typescript apple: {...

User VS Account

Hi there. I was looking into the hooks before and after account and user creation, and I was just wondering. what's the difference between the two objects? Thanks

Trying to understand the connection between client and server in Tanstack Start

I've been exploring/experimenting with Tanstack Start framework. I mostly have the auth working, however I'm trying to understand why the useSession hook is not working as expected (will not update when authentication happens, will update when logging out with the auth client). Is there something I was supposed to do to connect the auth client with auth server (-side implementation)? Doc's seem to just indicate it should just work as-is....

reset-password not working with email link

Hi, For some reason, my reset password email is not working - I have this code: ```ts import { resend } from "../mail";...
No description

Different redirect based on first time user or returning user sign in

Is it possible to change the redirect URL based on if it's the user first time signing in or if they are a returning user?
Solution:
Wouldn't a first time user be signing up instead of signing in?

Error generating backup codes

Hello, im trying to generate a backup codes for a user. But i have this kind of error when generating backup codes. How can i fix it ? Where did i do problem ? ```tsx...
Solution:
Yeah i switched to OTP

2FA Totp

Hello, i wanna add 2fa TOTP to credentials login. How can i generate a QR code for user to scan ?
Solution:
That's out of Better-Auth's scope at what we provide. You should find a library that does this
No description