Better Auth

BA

Better Auth

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

Join

bug-reports

help

Is there a way to sign in as an existing (previously created on the same device) anonymous user?

I have a scenario where I automatically sign in a user as anonymous once they land on my site using the anonymous plugin. I then allow them to sign in using their google account. But once they sign out of their google account I want to be able to log them back in as the existing anonymous user that was created initially when landing on the sit.

User email verification manually does not working

I have a button in my dashboard to send verification email to user. But for unverified user I see this error: You can only send a verification email to an unverified email `const handleUserVerification = async (email: string, status: boolean) => { if (!status) { const { error } = await client.sendVerificationEmail({...

How to use Better Auth with Cloudflare D1?

How to use Better Auth with Cloudflare D1? @Better Auth...

Can I create two better auth configs on the same server,I am using Elyisa Js

Have two sub domains a.domain.com b.domain.com I used a single better auth config and the sign up and sign process where working just fine....

Better-Auth jwtClient() plugin shows ERROR when used with expoClient().

Here is our authClientConfiguration: ``` import { expoClient } from "@better-auth/expo/client"; import { jwtClient } from "better-auth/client/plugins";...
No description

Next.js middleware not able to read better auth session token

I have the my Nest.js backend running on digital ocean vps with custom domain. The frontend is built with next.js, when I try to login in the application, I cookies are getting set as you see in the image, but the next.js middleware is not able to read/get the session cookies. This is working super good when we are running the backend on localhost, but on deployment this is happening. I have updated cookie settings with secure = true, samesite = none, httpOnly = false, partition = true. What am I missing?...
No description

How to implement passwordless login with phone number OTP in Better-Auth

Hi everyone, this is my first time of using better-auth I’m trying to implement passwordless login using phone numbers and OTP in Better-Auth. I have: 1. Enabled the phoneNumber plugin. 2. Sent a request to /phone-number/send-otp to get the OTP....

custom credential provider

yo waddup im using next.js and wanted to implement sth like the "custom credentials" in auth.js to use our seperate backend api to obtain response which includes stuff like jwt token, user id and .... but i had no luck findng any documentation related to it does any of yall know how to solve this issue...

Role value in userHasPermission function

Hi guy, I'm new to using Better Auth and working on a simple role-based access feature. I have a small question regarding the value of role in the userHasPermission function. As image, I have a user with the role cameraHdManagerRole. But when I use the userHasPermission function and pass in a different role value that does not match user's role, the result still return success:true. Why does it return true even though the role does not match that user?...
No description

How can I use better-auth with external authentication api (jwt/bearer tokens)

Hi is there anyway I can use better-auth as way to manage session and page protection with a external api that manages login? My current backend responds with a jwt token (bearer token) after a successful login how can I use this with better auth? I used to use next auth but that gave me issues because it didn't worked with the above properly....

Get access token on the frontend

Hello everyone! I'm playing with Better Auth using it to authenticate my app's user on Google. Everything is working smoothly but I noticed that there is a way for the user to get the access token issued by Google on the frontend by calling await auth.api.getAccessToken((...). I'm wondering if it is common practice to expose these tokens to the frontend. Is there a risk of this token to get stolen somehow?...

Google O Auth

Hello, hen i try signIn with social it dont redirect me to the google.. Why ? ```ts async function LoginOAuth(provider: "google" | "discord") { console.log(provider);...

[Error: Failed to collect page data for /api/auth/[...all]] coolify

I building my next.js app on coolify with nixpack but i get this error . [Error: Failed to collect page data for /api/auth/[...all]] what i can do ? @bekacru @Max...

Capacitor with Apple Login

I have a Capacitor app that has social login. I want to add apple login functionality, but the problem is that for some reason, apple sends oauth information as a POST request with form data for the code and state. Once I login on the apple side and it redirects back to my app, it has no state or code to be able to properly authenticate. Is there a solution that works for apple when it comes to better-auth and capacitor? P.S. It works fine with google and microsoft auth, just not on apple...

User with profiles belonging to organizations

Hi, is there a way to get this flow working? A user can have multiple profiles. A profile can belong to multiple organizations. The user is not directly part of the organization....

[Bug] Social Providers Login cannot pass user data

In hooks.before, I have added an id into the body: hooks: { before: createAuthMiddleware(async (ctx) => { const referralCode = ctx.body?.referred_by || ctx.query?.referral_code; if (['sign-up', 'social'].some((v) => ctx.path.includes(v)) && !!referralCode) {...

How to set cross domain cookies ? (Urgent please I have hackathon deadline)

So here is the scenario - I have my frontend on domain vibe.appwrite.network and api on vibeapi.mdhruvil.page , when I complete google auth flow it is setting the cookie in api domain but when I make request from frontend domain to backend domain it is not sending the cookie with request despite having credentials: true, Also I when I visit /api/auth/get-session on api domain it IS returning my session successfully.
API Auth Config - https://github.com/mdhruvil/vibe/blob/main/apps/server/src/lib/auth.ts ...

How do I link a user that already exists with an SSO login?

If I have created an account with user@acme.org, and then register an SSO provider for my domain, how do I merge the current account with the one provisioned when loggin in with SSO? I'm currently seeing this [Better Auth]: User already exist but account isn't linked to acme-google. To read more about how account linking works in Better Auth see https://www.better-auth.com/docs/concepts/users-accounts#account-linking....

Nextjs + Expo + Express API Questions..

I have a Nextjs app that's configured for for better-auth and working well. The Nextjs app talks to my express api backend for graphql and mcp calls. Now I'm building an Expo app and I want to authenticate users. I'm following the guide for Expo integration, but it's not clear to me if I need to setup better-auth in my express app or if I can use what I've already configured in my Nextjs app. I'm not planning on using the Expo api routes since I already have an express api, but I've also already configured Nextjs for better-auth. Do I extend my Nextjs better auth configuration to include the expo plugin OR do I setup better-auth in my express app with the same authentication configs (email/pass + oauth) plus the expo plugin?...

Limit user in organisation dynamically.

With the organisation plugin is it possible to restrict the amount of members dynamically. In our case we want to create an organisation by default when a user signs up, even in the free tier. However while in free tier that user should be limited to 1 "seat" / member, themselves. ...