Better Auth

BA

Better Auth

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

Join

bug-reports

help

Why does the session disappear after refresh?

Here, I am retrieving the session from authClient, but when I refresh the page, the session data disappears. What is wrong here?
No description

support both MagicLink and OTP

How to enable the verification by both ways together, client can verify either by entering OTP sent in email or clicking the "verify-link" can anyone help me on this, thanks in advance...
No description

Argument `id`: Invalid value provided. Expected String, provided ().

I'm making a plugin and got this error: `` prisma:error Invalid prisma.wallet.create()` invocation:...
Solution:
Im just stupid, wrote fieldname: "id" which broke it

how do you run a function after user creation?

i want to create a personal organization for users by default

How to trigger refresh/update of session if user info changed

I made a plugin to store some custom user info ```ts import type { BetterAuthPlugin } from 'better-auth'; ...
Solution:
finally got it working ```ts endpoints: { approve_user: createAuthEndpoint(...

google sign up page doesn't open

i tried to follow the docs. the google sign up page doesn't "open" for me to sign in... what could cause this?

error in trying to create database schema with the cli

Hey folks here is my better-auth config ```ts import { db } from "~/server/db"; import { api } from "~/trpc/server"; import { betterAuth } from "better-auth";...
Solution:
Likely due to your imports. Could you try this without your api import and just comment out all of the functions using it?...

One tap: Google One Tap is only available in browser environments

I use the google one tap api in my NextJS app still i get this error and the One tap doesn't pop up
Google One Tap is only available in browser environments
Google One Tap is only available in browser environments
...

Can an Anonymous use their anonymous account multiple times even after they close the app?

And also, when i use the signin anonymous api, an anonymous user gets successfully created in the DB but its doesnt log in the current unlogged session (user) to that user, meaning a new anonymous user gets created everytime this component renders without ever logging in to that user, And also, should i rely on the Anonymous user api if i wanna make a user have a seemless user experience without ever needing to log in? ```ts...

Only allow one active session at a time

Hi all, I am trying to implement a feature after a pay wall that requires user to have only one active session at the same time (if user tries to log in on another device, old device will be logged out) Please help to guide me a way, any idea is appreciated. Thanks!...
Solution:
Not sure if it is the best approach but I achieved this by deleting all the session for that user except the newSession in the after hook. @phipham

Delete User return db error

I want to delete a user, which is also the admin of an organization. Do I need to remove all admin, data manual? Can I also do a "soft" delete and just flag the user that he is deleted instead of removing him from the database?
update or delete on table "pd_user" violates foreign key constraint "pd_member_user_id_pd_user_id_fk" on table "pd_member"
update or delete on table "pd_user" violates foreign key constraint "pd_member_user_id_pd_user_id_fk" on table "pd_member"
...

SvelteKitError: Not found: /api/auth/sign-up/email

I'm using SvelteKit, and I encounter the following error when trying to sign up with email: SvelteKitError: Not found: /api/auth/sign-up/email. I have hooks.server.ts inside the src folder, and auth.ts and auth-client.ts inside lib. How can I fix this?...
Solution:
I implemented it in Sveltekit like this hooks.server.ts ```ts import type { Handle, RequestEvent } from '@sveltejs/kit';...
No description

Machine-to-machine authentication

Hi. Is there any way to authenticate machines ? We are building an app in the drilling industry with users authentication and machine authentication. Basically each drilling machines will send data and users will display those data. How could we implement machine authentication with better auth ?

Admin list users with extra properties

Hi, i am trying to use the listUsers admin method (it works fine btw) but I can't access other properties from my user schema such as orders, idk if its possible to do it, i hope so, here are my auth.ts, auth-client.ts and schema.prisma files
No description

Better Auth ABAC (not RBAC)

Anyone have an example of doing ABAC using Better Auth? Just curious.

Conceptual questions on an auth setup with sveltekit and a separate api sever

Hey guys, I'm currently trying to build a techstack for a small SaaS around sveltekit as a frontend and graphql-yoga as a backend. Now I am stuck on how to do auth properly. Unfortunately most example repos I could find use the backend from the meta frameworks and not a separate API Server, so I couldn't find examples on how I could implement this. At the moment I planned on installing the better auth server side stuff into the yoga server and obviously put the client side better auth stuff into sveltekit. ...

Server session untyped

We're currently in the process of migrating an AuthJS monorepo to better-auth, but off the bat are experiencing the returned value of a server side getSession being untyped. ```typescript const session: { [x: string]: any;...

Error in trying to handle better auth on the server only

I would like to handle better auth on the server only not the client. If I pass in the baseUrl and the basePath options to the authConfig, it is handling this for me and erroring on some pages

Secret not working

I have provided a secret_key to the bettwer auth config and it is still defaulting to better-auth-secret-123456789

Prisma transaction support

I have a user model with several other join tables. I wanted to keep everything in a transaction, how do I do that?