Better Auth

BA

Better Auth

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

Join

bug-reports

help

Drizzle generate creates default values as variables instead of strings

In the code below the default values for status in invitation and role for member ( member and pending) should be strings but are generated as variables. ```ts export const member = pgTable("member", { id: text('id').primaryKey(),...

GET /api/auth/get-session

when i wanted to open my dashboard i see a lot of calling the session (it not in a loop) iam using nextjs and server acttion this is how i get the session :get session in use client: import { useSession } from "@/auth-client" const session = useSession() const userId = session.data?.user.image ...

Enable/disable email sign ups programatically

Is there a way of programatically turning email sign ups on and off? Right now the only way to do it is with the options for the email sign up, but this is cannot be dynamically changed: ```js emailAndPassword: {...

HELP: How to have both email & password and Google set up?

Hi. My client signed up for my service with Google and wants to let his employees sign in with an email and password so they don't have access to his email login. They signed up with google first and then when they try to make an account/login with email and password it doesn't work. ...

Error: proxy request failed, cannot connect to the specified address

I'm getting this error on my production build on Cloudflare Workers. Here is the source code https://github.com/safecircleia/waitlist all enviroment variables are setup correctly and it works locally ```less...
Solution:
Ok, I just needed to add enviroments variable in the runtime options not just in the build configuration

Better-Auth OAuth flow automatically accepts the OAuth request

I can't even click to accept or confirm myself, the bottom right blue button is clicked for me and the request immediately goes through. Like, I don't even have time to read the information...
No description

Next Hono session is empty

I do not know how to structure this question to be honest, But is there a way to get the session details or another way to check if the user is logged in ? if the frontend and backend is hosted on seperate server ( ie: auth.ts file is not available at next frontend side). in the image: 1. backend is the hono application 2. users is the frontend nextjs application...
Solution:
So to digest the issue was I was logging in from a server component which did not set the cookies in the nextjs application. which would not be a problem if I was using hono as a replacement of the next api router, where nextCookies() plugin could be helping while the logging was happening from a server component. but in my case i am not replacing the next router .. i am having a seperate hono server so i guess the plugin nextCookies would not reflect to the next server ...
No description

JWTClaimValidationFailed: "iat" claim timestamp check failed (it should be in the past)

I have a bunch of test devices and all of them work perfectly fine 100% of the time. However, I have an older device that for some reason has an out-of-sync clock by ~+700ms. Sometimes when logging in the iat claim will be invalid because the server trip takes ~30ms meaning the iat was produced in the future. It looks like I can fix this use jose's clockTolerance option (https://github.com/panva/jose/blob/main/docs/jwt/verify/interfaces/JWTVerifyOptions.md#clocktolerance), but I can't figure out how to pass this via better-auth. Any ideas?...

Elysia backend + Nextjs frontend, getSession issue

```ts import { headers } from "next/headers"; import { authClient } from '@/lib/auth'; ...
No description

Typescript doesn't like my new role of "approved"

I've extended the type according to the docs: ``` import { db } from "@/server/db"; // your drizzle instance import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle";...
Solution:
Am I looking at "roles" wrong? I want people to be able to sign up, whcih gives them the "user" role, but I don't want them to be able to do anything until they get approved by an admin. Currently I am setting a role of "approved" on them (a custom role with the ac stuff). Is that the normal flow? is this the same perms as the userAc?...

delete user using api

How do I delete a user from the API? Assume I have some "admin" permissions or an api call like delete-user, I check an api token, can I not call a betterauth method for deleting? Admin plugin requires a user to be logged in with admin permissions Default has deleteUser, but its meant for a user deleting their own account. ...

How to tell if user is new signup in auth hooks?

Can we do this via Better Auth or do we have to call the db to check? If so how do we get the values to to actually check the DB?

MFA depending on user role

Hi! I was wondering — is it possible to enforce MFA for admins, while keeping it optional for normal users?

What im missing?

Im using Github provider on next js and hono for api, hono runs on different port, since is used outside of next js, and not nested like it can, but i can login, but then i get this callback ERROR, where im doing something wrong ```ts import { createAuthClient } from 'better-auth/react';...
No description

Why does better-auth want my users to have a name?

authClient.signUp.email requires a name to be provided and added to my user table. How do I turn this off?...

nextjs + external express api setup help, getting 403

Hi! 👋 I am getting invalid origin 403 from authClient methods like signIn and signUp. I want to have Nextjs as frontend and express server separate as an API, including the better-auth routes ...
Solution:
add trustedOrigins to your api auth.ts
No description

Stripe Subscription Status in JWT Payload

Hi everyone. Just wanted to see if anyone has successfully added the status of a users subscription to the JWT payload. I think I read somewhere that you can't add additional details to the JWT payload if the detail comes from data managed by a plugin (in this case the stripe plugin).

better-auth passkeys + coinbase smart wallet? question about compatibility...

Hi everyone! 👋 I was stoked to see the recent tweet about the new Coinbase x402 plugin – excited for this direction for better-auth, looking forward to more web3 stuff (like SIWE?) I was looking into how to integrate better-auth passkeys with a smart wallet system, specifically aiming for something like the Coinbase Smart Wallet (or similar stuff like accountkit/pimlico -- they all use viem or Oxlib under the hood i think). ...

API Request errors for better-auth on Cloudflare Workers

Hey! Has someone gotten better-auth to work on cloudflare workers? I am trying to deploy a Nuxt 4 application (via NuxtHub) to cloudflare workers, deployment works, but better-auth fails on requests to API endpoints, despite it working flawlessly in development, so this must be cloudflare-specific issue. I consistently get: CLIENT ERROR: POST https://app.netzo.dev/api/auth/sign-up/email 500 (Internal Server Error) SERVER ERROR: SERVER_ERROR: TypeError: Cannot read properties of undefined (reading 'includes')...

Add user without ending session

I’m adding user via server api big the dude effect is it changes the session to that user. How to prevent that? I realize there’s that manager plugin that may do this but I don’t need all of that (I’m doing my own role things)...