Better Auth

BA

Better Auth

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

Join

bug-reports

help

resetPassword & autoSignIn

I can see in the doc that autoSignIn is for "after sign up". But could we have a flag for autoSignInAfterResetPassword ?...

emailAndPassword sign-up error in Nodejs-Express

- The user was added to the DB, but the api responded with error [500]. - [Better Auth] ERROR The field "expiresAt" does not exist in the "account" schema. - Session was not created after sign-up The schema was generated with the CLI and No "expiresAt" on the account table....
No description

Using existing DB schema with Drizzle

I created a schema for the better auth table called better-auth which I'm passing as auth options to the drizzle adapter. However when I run the cli command to generate the schemas, the better-auth schema isn't being used. Is there a way to use the custom schema I created? The following is my authOptions which I'm sharing between the actual auth instance and a fake one which is used with the cli. ```ts export const authOptions: BetterAuthOptions = { database: drizzleAdapter(...

cookie cache additional fields

It doesn't appear that additionalFields in the betterauth config extend to cookie cache.

getCookieCache returns null?

So I am using NextJS, and have set everything up. For the most part BetterAuth works awesome. I want to use the getCookieCache method, so I enable cookie caching in my auth.ts. However, when I look at the docs, and implement the middleware check, my getCookieCache is always null, even when there is a session....

Inferring types on the server

Is it also possible to infer the return-types of specific API routes on the server? I am creating a better-auth wrapper using effect-ts for my application and am missing some type-safety on the server. ```ts...

Personalize Auth Flow

Can I build a auth modal where users can signup with google then redirected to my app to enter required info like username, bio... ?and at the end let them access the app

OAuth login provider refreshToken and impersonate

Hi guys, I'm wondering about a particular setup i have The users logs in using a Keycloak instance I can then impersonate them and make use of the JWT plugin to construct a custom payload for my backend services based on the user accessToken issued by keycloak...

Fresh Next better-auth drizzle mysql error

``` dialect.ts:75:3) { code: 'ER_BLOB_KEY_WITHOUT_LENGTH', errno: 1170, sql: '\n' +...

How to use metered prices with better auth stripe plugin

I’ve some metered prices in stripe but when I try to manage a subscription I get this error: "Quantity should not be specified where usage_type is metered. Remove quantity from line_items[0]" How can I charge for usage ?...

How to wait for new auth data to populate useSession state?

I'm trying to redirect after a login, but the session variables aren't updating soon enough to be used in any of my route guards, who think the user is still logged out. Currently I'm fixing it by adding an await $auth.refetch(), which works, but results in an extra trip to the server, and isn't part of the it's public types (I just happened to stumble on it). Is there anything else I can wait on? I kinda expected to be able to await the signIn.social call and know that the store would be up...
No description

Next.js: useSession() hook does not seem to refresh when session is changed from the server

Hey everyone, I am currently working on adding a login system to my Next.js website. So far everything is working as expected, but I ran into some trouble when trying to automatically redirect users from e.g. the login page to the dashboard after they've clicked the magic link for example. Here's some information: - Sign-in is called from a Server Component using the API. - Sign-out is also called from a Server Component....
Solution:
Perhaps this is simply not the right usage for useSession, since it does work with a cookie and the server cannot reactively send new info to clients without a refresh. I just added a 5000ms polling effect and it does the trick
No description

list organizations that user is a member of, but on client side

in docs i only found the client side hook to do it but how can i do that on server side? when i call listOrganizations it says 'UNAUTHORIZED'...

SAML SSO Plugin Help

I've gotten all the way to the point with the new SSO plugin. When i click the button that's attached to the authClient.signIn.sso, I redirect to a page with JSON: {"redirect":true,"url":"https://login.microsoftonline.com/<idp-id>/saml2/dashboard"} I'm not understanding where the 302 redirect is supposed to happen if at all here. I've followed the beta docs (minus using the spMetadata function due to it not building the xml correctly with the entityId). ...

Is there a way to get the additionalFields in the useSession hook?

I dont know if this has been asked before (couldnt find anything in the search, but is it possinle that if i add an additional field (call it role, like in the example) that i can see it in the useSession hook?

`useNumberId` is set, but `id` is still a string?

Hey, I'm using useNumberId: true in my betterAuth config (with an SQLite database), but I'm still seeing that the user id is a string in my auth middleware. Did I miss something ? Thanks in advance :). ```typescript...
Solution:
In order for existing plugins and libraries that work around Better-auth to continue to function, the id value has to remain a string. Our adapter system will automatically convert the id from string to int and vice versa when interacting with DB....

e2e nextjs

Anyone got some working example how to login with login/pass to better auth in nextjs? Using playwright. Tried setting cookie manually but it apparently is not enough, auth.api.getSession still returns null thanks in advance...

Is there a superadmin role that lets you manage every organization?

hey guys, I'm building an admin portal for my company's project. We need to be able to manage (delete/edit/send invitation) every organization even if the operator is not in that organization. Is it possible in better-auth?
Solution:
https://github.com/better-auth/better-auth/issues/1595 Turned out it isn't available yet. I added a hook on /oauth2/redirect to automatically add users logged in through our internal IdP to a special organization, then added a server action to directly modify the database if that user is a part of the special organization. ugly but it works 😅...

Trying to revoke a session server-side.

Hello! I have been trying to revoke a session server-side, I figured I could try to use: ```typescript const result = await auth.api.revokeSession({ method: "POST",...
Solution:
If anyone else needs this: - Install the bearer plugin - Create a headers object - Set Authorization: Bearer <token>...

Cross Domain : Receiving null for both data and error while fetching session

I have a nextjs frontend and a hono backend both hosted in ec2 instance through docker. While logging in the cookies are being passed and stored in the browser, but after loging in the user is redirected to dashboard page where i use
const {data,error} = await authClient.getSession({fetchOption : { header : await headers()}})
const {data,error} = await authClient.getSession({fetchOption : { header : await headers()}})
...