Better Auth

BA

Better Auth

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

Join

bug-reports

help

The inferred type of 'authClient' cannot be named without a reference to [email protected]

Currently having an issue with undici:
The inferred type of 'authClient' cannot be named without a reference to '.pnpm/[email protected]/node_modules/undici-types'. This is likely not portable. A type annotation is necessary.
The inferred type of 'authClient' cannot be named without a reference to '.pnpm/[email protected]/node_modules/undici-types'. This is likely not portable. A type annotation is necessary.
My auth client:...

Init Drizzle with cloudflare env variables

I'm trying to connect my database with the drizzle adapter. My backend will be hosted on cloudflare workers (with hono) so I can't use process.env to get my environement variables. How to get my cloudflare env variables to the db init ? Thanks for your help! ...
Solution:
```ts import { drizzle } from "drizzle-orm/d1"; import * as schema from "./auth-schema"; export const createDrizzle = (db: D1Database) => drizzle(db, { schema });...

Stripe one time payments?

Hi everyone. Is there a way to utilize products with the stripe plugin. I understand that subscriptions are the focus of the plugin atm. I need this soon and don't mind creating a plugin for it.

Error in auth with discord

When I try to log in with Discord, it doesn't redirect me to the login page. And the API route even returns that: ```` 0:{"a":"$@1","f":"","b":"development"}...
Solution:
i got fix that 🙂 i added endpoint for my api, and add onSucess in signin haha 😄...

create organization in databaseHooks.user.create.after

I want to ensure that for all created users without an invite link, an organization (using the organization plugin) is created for them automatically on sign up. Ideally also set this freshly created organization as their active organization on the client. Is there a way to create an organization for a user that has just been created? I was thinking of using this database hook: ...
Solution:
To follow up ^^, here is how you can create org from server auth api:

Can BetterAuth’s OIDC provider work with Saleor as an external auth system? If so, what’s the config

I need help from someone who has been able to setup a working OIDC with Better Auth. Thanks

Ip address and same browser verification between otp/magicLink trigger and verification.

I trying to check the IP address of magic link trigger and magicLink verification, both the ip address need same. And also trying to implement one more case where both the magicLink trigger and MagicLink will be happening in the same browser, if magicLink verification happens at different browser, the i expect the verification not to happen. Can you please help me in this?...

cant find table column that i added to the user table in session

so basiclly i modified the user table and added a phone field but when i try to display it using the session hook useSession i get an erreur that the property does not exist on type user i added the additionalFields in the auth.ts file and i can successfully signUp and the phone gets added to the user table ```javascript <div className="flex flex-col space-y-0.5"> <p className="text-sm font-medium">...
Solution:
Have you added the additionalFields plugin on your client auth?

Core Schema Adjustment - ID Data type from text to UUID

Hey guys I really can't find any way to fix this. I want to change ID data type from text to UUID but there is no option for this. I use nextjs + postgres + kysely Any ideas?...

how rememberMe works?

hello, how does the rememberMe work (on the client)? Do I need to call anything to "login" with saved session, or just instantiating the client is enough for it to use a saved session (eg getSession and useSession return the correct session)? Or do I need to manually pass headers/token to some other function? My use-case is, there could be more than one server. So the client instance/baseURL can change. But if a user was logged in on a server I want him to automatically login. (I already have all the "info" about server and if it is logged in on that server in localstorage, but I don't know the betterauth api to do this) My idea is: if a user changes the server, all sessions are revoked....

Change `id` field name?

Hi, I created my database schema before working on adding Better Auth, and I had decided to call the "identifying" id fields of my users uuid, for clarity. Is there a way to tell Better Auth to use uuid as the used field name? I saw that you could change other required field names, but not this one.

Change the frontend of the Better-Auth API error page

Is there a way to change the frontend of the Better-Auth API error page?
Solution:
you can pass a custom page url onAPIError.errorURL

Admin plugin

I am logged in but see ```js { data: null, error: { code: 'UNAUTHORIZED', status: 401, statusText: 'UNAUTHORIZED' }...

admin plugin generates invalid prisma schema

after running
npx @better-auth/cli generate
npx @better-auth/cli generate
i got this error in the schema.prisma
Error validating model "User": Ambiguous relation detected. The fields `Session` and `sessions` in model `User` both refer to `Session`. Please provide different relation names for them by adding `@relation(<name>).Prisma
Error validating model "User": Ambiguous relation detected. The fields `Session` and `sessions` in model `User` both refer to `Session`. Please provide different relation names for them by adding `@relation(<name>).Prisma
...
No description

INVALID_ORIGIN when I try to check organization slug or create

I am not able to check slug, create new organization etc. I always getting and 403, but sign-in works fine
Solution:
add your frontend url intrustedOrigins list on your auth config

Integrate betterAuth with React-Router v7 cloudflare template

Hi, I am currently using RR7 framework mode with cloudflare template. This template allows you to use all of the services from cloudflare in action and loader through a prop. For example, let's say you need to use KV store from cloudflare in your RR7 app. You can do something like this: ` export async function loader({context}: Route.LoaderArgs){ const value = context.cloudflare.env.SECOND_STORAGE.get(key) //SECOND_STORAGE is binding name to use KV store //Do something...

How can I prevent rerendering while changing route

I am currently using the app router in next.js but its rerenders everytime when I change the route, how can I prevent this. here my authClient and my Organization Switch as file added as well. ```js...

On-boarding step after social login

Hey! I m using google social signin and i give new users the 'pedning' role attribute in my database, I want to redirect these type of users to the onboarding page whenever they try to access anything in my app. where i collect additional infos about them such as to setup a displayname. , so basically not allowed to skip this step, then i change their status to something like 'member'. i want to know if there is a way to get the authenticated user data in my middleware so i can read their role status and redirect accordinly isntead of spamming all my pages with this check ? or any other method. thank you !...

why the ipAddress config is used

at the betterAuth we have config for ipAddress ipAddress: { ipAddressHeaders: ["x-client-ip", "x-forwarded-for"], disableIpTracking: false },...

Re-sending verification link after verification token expires

What's the correct pattern to allow re-sending a verification link if the user waits until after the verification token has expired to click the verification link? (1) - UX pattern - I could check the query string for error=token_expired and provide some UI where they can enter the email address they signed up with to get a new verification link sent to them. Is there a better UX here? (2) - generating verification token - not sure how to generate the token that sendVerificationEmail expects...