Better Auth

BA

Better Auth

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

Join

bug-reports

help

How to refresh session after changing org in Nuxt?

Using the following
const { data: session } = await $auth.useSession(useAuthFetch)
$auth.organization.setActive({ organizationId: org })
const { data: session } = await $auth.useSession(useAuthFetch)
$auth.organization.setActive({ organizationId: org })
...

How to redirect to `/sign-in` on all urls if unauthenticated

Hey there! I’d like to redirect unauthenticated users to /sign-in if they visit any url (except /sign-up). I see on the dashboard example...

Preventing Account Spam in BetterAuth (Free Credit Abuse) ?

Hello. We're using BetterAuth and offer free credits on signup. The issue is users can create multiple accounts to abuse the free credits. How should I implement protection against this using BetterAuth? What would be the best practice, or is there maybe a plugin for this case? Thanks.

How to handle email verification in Express and React?

Hi everyone! I am trying to implement email verification after the user's signs-up for the first time, I am using Express and React both in Typescript, this is the code that I wrote to handle it in the better-auth config inside auth.ts file server-side: ``` // Email configuration emailVerification: { expiresIn: 60 * 60,...

Alter default user schema, remove image field from it

Hi, is it possible to alter default user schema, from postgres i removed image field and i want to do to same in here: ```js export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql",...

Error when update API Key

got this error when tried to update api-key but create, delete, list is work fine, how to solve this? here's prisma ```prisma model Apikey {...

Cross domain auth

I have a scenario where a single hono api serves different frontends the api is at domain a.com frontends are at domain b.com, c.com, etc I set config like this...

Better Auth Fastify Integration Guide

https://www.better-auth.com/docs/integrations/fastify How exactly is this supposed to work? First of all, the documentation is very limited, it tells you to create the catch-all route, but it doesn't list what routes the handler even supports. Are you just supposed to guess or something? What's the idea here?...

getSession is not returning userAgent

I've been trying to set up a multisession feature so users can revoke access on other devices session. But getSession it not returning userAgent nor ipAddress. I even followed the Better Auth report example.
Solution:
Yeah, I create a server action and passed the headers when calling the function. ```export const getSessionData = async () => { try { const headersList = await headers(); ...

Auth client not working in Expo

Hi, I have a very basic setup with expo based on the documentation, when I try to sign in using the client, I get this returned.
{"data": null, "error": {"status": 0, "statusText": ""}}
{"data": null, "error": {"status": 0, "statusText": ""}}
...
Solution:
I figured it out, had to put in http://10.0.2.2 as the base url. Otherwise the Android emulator can't access the localhost. But I think the client should return a proper error message in this case....

Generic OAuth custom authorization logic

Hi there! I am using the Generic OAuth plugin in Nextjs with Hubspot and need to add some functionality that will deny a user access based on their email or associated user info, preventing these users signing up/accessing pages covered by the middleware. Is there a nice way of doing this without getting the session in the middleware and denying based on data? As that requires a database call....

Callback that activates when a new user is created? (docs are not accurate)

The docs suggest the following to listen to when a new user is created: ``` export const auth = betterAuth({ hooks: {...
Solution:
Solved. Use databaseHooks -> user -> create -> after.

Enforce UUID v4 format for user ids?

Is it possible to force user ids to be UUID, or have some sort of hook that enforces user ids? I'm asking b/c Apple's appAccountToken must be a UUID....

What is FieldAttribute.sortable ?

The context for this question is ORM adapter writing and schema generation. What is the sortable prop intended to be? Thank you!...

cannot understand the use of checkRolePermission is organization plugin

As title says. As far as I can under stand it check if certain role have some permissions or not. Shouldn't it work as if a user have the role and the permission? if not can someone provide me an example of this function and how it's helpfull?...

Manually Extending Auth Types

Is there a way to manually type or extend the authClient so that it can infer other plugin features. I have a function that accepts authClient but it can only access email plugin like so: authClient.signIn.email() , it's unable to infer something like authClient.signIn.magicLink. Is there a standard way around that? (I suppose the same question for the server auth too)

refetch() from useSession() return cached data

Why does calling refetch() from useSession() return cached data? This only happens in production. The updated data is returned after approximately 50 seconds. In development, it always returns fresh data immediately after calling refetch()

Stripe cancel and duplicate key value violates unique constraint

Hi there, I'm trying to add Stripe to my website and I found something strange. I guess I forgot something, but can't find the info... so: I have that button which call ...
No description

Invite user to organization (signed or unsigned users)

how to handle there cases: - we invite users to organization but user might not have an account, in that case check the user email and force user to signup then redirect to accept invitation page - but if user already have an account then redirect to login page if not logged in and then to redirect to accept invitation page...