Better Auth

BA

Better Auth

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

Join

bug-reports

help

ERROR [Better Auth]: State Mismatch. Verification not found

Hey! I am getting the the callback error screen for Google (/api/auth/error?error=please_restart_the_process) in a couple situations: - If a user is authenticated on a mobile device using Google Chrome and hits the "Desktop site" option in the Chrome page settings - A user is goes through the sign in flow with Google, selects their Google account, is authenticated successfully, but then hits the back button to go back to the Google account select screen (https://accounts.google.com/o/oauth2/auth/oauthchooseaccount?), and then selects the same Google account. ...
No description

Hono dosen't set cookies, so session returns Null

As you can see when I get mu session from the browser there is a session. Once I call the endpoint in nextjs using betterFetch or fetch the session returns correctly but in the server It dosent work as expected
No description

Maintaining session in a webview.

I'm building an expo app with a nextjs companion app. There are some components that are not available in the react native world and I'm consuming them through a web view. The page that is consumed uses client and server side trpc calls to fetch data/ mutate. Is it possible for me to maintain the session from the expo side inside the nextjs page? On expo i have this ```
const cookies = authClient.getCookie(); const newSource = { headers: { Cookie: cookies },...

OAuthProxy with branched database

I have the following config: ```ts export const auth = betterAuth({ database: drizzleAdapter(db, {...

Handle check email verified

How do you handle the check if the account is already verified? I cannot access this data in the middleware and I am redirecting after the user navigated to a specific page which feels super off. Is there any better way?

Email verification

When signing in with the requiredEmailVerification option on, if the user didn't verify his email address yet, a verification email is automatically sent. This means that the user could spam the sign-in button and/or route Is there any way to prevent that? I guess I could define a custom ratelimit for the sign-in route, as shown here: https://www.better-auth.com/docs/concepts/rate-limit#rate-limit-window but it's not really what I'm looking for. I don't want to ratelimit the route, I just want a cooldown on the verification email...
Solution:
I ended up doing exactly that, creating a new column in my db. This is what is looks like: ```tsx const throwInvalidCredsError = (isEmail: boolean) => {...

Organizations plugin with Drizzle RLS

Hi, I am creating a hobby project which is a multi tenant app (using the organisations plugin). I use Hono to serve a CRUD API. How can I: - Restrict certain columns to users with certain roles (keeping in mind a user can belong to multiple organisations with different roles between organisations) - Make sure users can only retrieve records which belong to their organisation(s)...

Magic Link Tutorial missing something??

I believe I've followed all the steps of all the tutorials for getting Magic Links working with svelte kit. When I submit the login form i created, which calls authClient.signIn.magicLink() I get the error Not found: /api/auth/sign-in/magic-link. No where in the tutorials is it mentioned what needs to exist at this endpoint. I can't find any mention of the this route in the codebase. What am I missing?
Solution:
Are you sure you followed these steps: https://www.better-auth.com/docs/installation#mount-handler ? This makes sure all routes belonging to better-auth are handled by better-auth

Admin Users Count

Hi. I am currently trying to get just the count of admin users. My query looks like the following: ```// Admin count query - separate optimized query just for counting const { data: adminData } = useQuery<UsersResponse>({ queryKey: ["users-admin-count"], queryFn: async () => {...

How to securely host a pg DB for better auth

I have a server I want to host Postgress for Better Auth. The internet keeps telling me "Don't expose your DB to the internet", but my website is on Vercel; which is on the internet. I could expose my Postgress LXC-container to the internet, but that seems like bad practice. ...

Issue with Google OAuth in Expo with Hono backend

I get this error when I select my Gmail account with which I want to sign in. My backend auth: ``` import type { InferSelectModel } from "drizzle-orm";...
No description

Use the admin and organization plugin together

I would like to use the admin and organization plugin together, how should I configure access control roles? I saw that it is configured in both plugins with import { defaultStatements, adminAc } from 'better-auth/plugins/organization/access' and import { defaultStatements, adminAc } from "better-auth/plugins/admin/access";

I want to disable updateAge for session expiration

I have two queries 1. I dont want the session expiration to be extended automatically with updateAge . I want the session to be only extended when the session is used. 2. i want the to keep the session alive/extend for just a specific page, so i was thinking of creating a dummy api and keep hitting it at interval to keep the session active if 1 is acheived. lmk if there is a better way....

How can i get email from resetPassword

```ts const { data, error } = await authClient.resetPassword({ newPassword: password, token: token as string, });...
Solution:
Oh just use the token and find the session in your db, and based on that you get the userId, and then you can get the user from that

SignIn Anonymous on Server

Is it possible? I dont see it on docs
Solution:
all authClient endpoints are exposed by auth.api and this can be called on the server

No cookies set when using the signInEmail method

Hello, I have configured Better-Auth to connect with email/password. The information passes correctly to connect the user, the associated data is returned. However, no cookie is set in the browser, so I can't return anything with getSession... ...
No description

[magicLink - drizzleAdapter] The \"payload\" argument must be of type object. Received null

Hey guys, I am struggling to get to the bottom of this issue. I am hosting my backend with open-next - THis means that it's hosted in a lambda which shouldn't affect anything - My other DB functions work just fine. - All envvars exist - My implementation works locally. - My hosted database connection works as expected in other parts of my app...
No description

Org plugin is ignoring additional fields on teams

I added a slug property to my team schema, but its not being passed when i actually try and use it ```ts export const auth = betterAuth({...
No description

RBAC

i need someone xplain me why this not works ```ts import { createAccessControl } from "better-auth/plugins/access"; import { defaultStatements, adminAc } from "better-auth/plugins/admin/access";...
No description

Expo setup error

Hi, I get this error when I change my metro and babel config. I got it when I changed only metro config and when I added "babel-plugin-module-resolver" I still get it. My metro.config.js and babel.config.js:...
Solution:
I fixed it by removing this line from metro.config.js: config.resolver.unstable_enablePackageExports = true;...
No description