Better Auth

BA

Better Auth

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

Join

bug-reports

help

Social Auth throwing 500 error's

When i user tries to login using OTP it works fine and returns success however if a user tries to login using social auth (google or microsoft) it fails (throwing a 500 status code) there is not logs relating to auth errors though and everything looks correct. Social auth logins did work at some point and has started to fail. I am using the auth client on my api using Hono and cloudflare workers and my frontend is using nextjs please see the attached files or these links here: ...
Solution:
Turns out my db wasn't running for some reason and it wasn't erroring out which is super weird oh well fixed now.

Hooks - session and newSession are both `null` after signin

I'm using an after hook to run some middleware after signing in a user. The user is able to sign in successfully, however both the session and newSession objects in the context are null. What's going on here? My expectation is that newSession would be defined with the new session for the signed-in user....

URL issues in social auth between Expo Frontend and Elysia Backend

Hey everyone! Setting up better-auth for an app, and there's an issue I'm facing. On web, while running expo, after trying social login using github, I get redirected to my backend rather than the frontend. I've setup the frontend (on port 8081) like this:...

getting unauthorized in production but locally works flawless

Hello. Im trying to implement a user check in one of my api endpoints in Hono to prevent abuse. The whole auth flow was setup on nextjs side (logging in, signing up etc.). But i neeed separate backend to manage high uploads. And the problem rises when trying to fetch that protected endpoint. I fetch it client-side with credentials "include" to attach the cookies. After fetching, i always get 401, and the credentials are set to "omit" for some reason. This didn't happen in local. ...
Solution:
Got it working now after 7 hours. I needed to hard reset browser and remove all cookies for this to work. Something weird probably cached. The code was good.

unauthorized error on next js api routes

I'm getting this error on my api route

What am I doing wrong? Cookies aren't working properly

Hono (Backend Code) ```typescript export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql",...

Getting session in loader

Hi all, I'm trying to validate the session in my route loader. I can't see anything in the docs about this, so I did it like this `export async function loader({ request }: LoaderFunctionArgs) {...
Solution:
Solved the problem — the better-auth session cookie was not being passed during login.

Set user account to verified=true after a password reset action?

User goes to reset password, receives password reset email, successfully sets password. However, account remains verified = false. What hook can I use in this context to set verified = true? The user has 'effectively' verified their email through this action. I've got it working after a magic email link sign in since that creates a user session and can access user object. Can't figure it out for a password reset where a session isn't created....

OIDC /oauth2/authorize doesn't work / throws 404

Hello, I'm currently working on setting up an OIDC Provider for an internal app (which serves as a central hub app, implementing a custom authentication solution that's exposed via better-auth plugins and should be available as an OAuth endpoint for other internal apps relying on the same authentication data). The authentication API itself is exposed on an express app / backend, whereas most of the client functionality (signing in, managing credentials) which all works flawlessly. I've hit a roadblock, because the OIDC Provider /oauth2/authorize endpoint simply does not work. I've tried everything from using the generic example from the docs, to tweaking every single setting....

Middleware not working?

Hi all, i guess i have a very common use case. but as i am new to better auth maybe you can give me some hints. Stack T3 Stack with better-auth, drizzle, trpc. ...
Solution:
then i tried to use the code for older nextjs versions ``` const { data: session } = await betterFetch<Session>("/api/auth/get-session", { baseURL: request.nextUrl.origin, headers: {...

JWK must be an object

Hi all, getting the following error trying to use the JWT plugin... any pointers? SERVER_ERROR: [TypeError: JWK must be an object] GET /api/auth/get-session 500 in 823ms ...

How do you add an existing member to a team

Hey, i was wondering how you would add an existing member in an org to a team. the docs don't seem to cover this.

Is it necessary to configure something for the typing of additional fields to work in the orgs?

As per the screenshots, I created an additional field(role) for the user, but when checking the typing of the returned user object(allowUserToCreateOrganization), the additional field is not there. For the client, I configured it with inferAdditionalFields and it worked perfectly. However, I couldn't find anything similar for the organizations plugin....
No description

Why is the token set in the browser different than the one in the session table?

For some bizarre reason the browser sends hmMN3f2wYkM6X3RC1Kxxxxxxxxxxxxxxxxx.TEM86Y81I1WpCxxxxxxxxxxxxxx= but the session table only has the first part, hmMN3f2wYkM6X3RC1Kxxxxxxxxxxxxxxxxx so I need to manually split it in my backend to verify it against the db. Why for godsake?...

Connections to organization

Hi all - wondering if there is a way to connect OAuth connections - like Google and Slack, to an organization rather than to a user with BetterAuth? or would have to be custom
Solution:
It's not possible. You'll have to make this yourself, sorry. Can I know your use-case though?...

Cleanup of expired organization invites

Hi, I've noticed that there are a few places where better-auth generates records e.g. organization invites where they expire. How does better-auth go about cleaning up expired records when they're created?

Get Members of an Organization

hey, could someone explain what this function does? https://www.better-auth.com/docs/plugins/organization#get-active-member I want to list all the members in the organization.. how do I do that?...

Microsoft login not working

Might be being mega dumb here but I have followed the docs and trying to have just a Microsoft login. Clicking my "Login with Microsoft" button just loops me from /login back to /login? and the only thing that happens in my DB is a record created in the Verification table. Why wouldnt this be signing me in or creating me as a user?...

membershipLimit for Organizations

Hi, I can see that it's possible to set a limit for team members but is this possible for Organizations?
Solution:
You might have it the wrong way around, we have a membershipLimit, but no team member limit

Session Not Persisting in Production (Docker) After Social Login

Hi, The authentication flow using better-auth and social login works perfectly on localhost. When I log in with a social account, the session is correctly created in the database, and the user appears as logged in on the site. However, when I run the same setup in production inside Docker, the session is still created in the database, but the user does not appear as logged in on the website. It's like the session is not being recognized properly in production. ...