Better Auth

BA

Better Auth

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

Join

bug-reports

help

Sveltekitcookies type error

When I add following code ``` export const auth = betterAuth({ // ... your config plugins: [sveltekitCookies(getRequestEvent)],...

Discord Redirect

Hi! I have a question: how can I force a redirection to the OAuth login page (Discord in my case) from a server-side action?

Infer additional organization fields on react client not working?

When accessing the useActiveOrganization hook, the additional fields are not showing. The backend is working as expected for inserting the additional fields, however frontend inferrence is not working. I am getting a Property 'type' does not exist on type Prettify<{ ...core org fields }> ```...

Cannot use useSession hook

Hello, I use Better Auth with Next.js. I use the Discord provider and it works but when I want to retrieve the user's session, my IDE tells me that authClient.useSession is not callable and I got this in my browser's console: GET http://localhost:3000/api/auth/use-session 404 (Not Found). My file src/app/api/auth/[...all]/route.ts looks like this: ```ts...

Base URL not working.

I pass the following: ``` export const authClient = createAuthClient({ baseURL: "http://localhost:6600",...

Client-side useSession() not updating upon sign-in

I'm using SvelteKit form actions to handle sign-in (with the new sveltekitCookies plugin), but after I sign in, my layout doesn't update until I refresh the page. Looking at dev tools, the cookie is set properly right after sign-in. Any help would be appreciated! +page.server.ts ```js import { auth } from '$lib/auth';...
Solution:
if you sign in on the server side, useSession doesn't know that. If you did the signIn using authClient, useSession would know. What I would recommend is after calling the server action, on the client call refetch: ```ts const { refetch } = authClient.useSession(); //. ^...

No response for generic oauth api

I am using nestjs, prisma and nestjs, was implementing custom OAuth but when I hit the api I never get any response from the api /auth/sign-in/oauth2. Where do I start debugging?

Session Error

[ Server ] Error: Invalid db[getModelName(model)].update() invocation in /Users/mkrakel/Projekte/app.legalbot.de/.next/server/chunks/ssr/node_modules_better-auth_dist6657fa..js:7765:62 7762 }...

Additional Fields relational

My Old schema had a links entry that had a one to many relation, how do i replicate that with betterauth's additionalFields?
No description

Can I setup BetterAuth without a DB?

My Backend is managing by other team with Java Spring boot and my frontend is Nextjs and expo, I want to use BetterAuth but seems docs says I need to have a db, but my DB is managing by other team so why I need a db, why it can't work like Next Auth!! or am I missing here??

How to catch validation errors when using a zod schema in an endpoint

I prefer adding a Zod schema to the create endpoint body param when creating custom plugins with API routes. It provides great DX, however, I cannot figure out how to catch validation errors. I always receive “Invalid body parameters”....

Argument of type is not assignable

Hello! I just updated to Better Auth v1.3 to try out the new SvelteKit cookies plugin, I'm using the code on the changelog but I'm getting this problem on getRequestEvent in VS Code: ``` Argument of type '() => RequestEvent<Partial<Record<string, string>>, string | null>' is not assignable to parameter of type '() => Promise<RequestEvent<Partial<Record<string, string>>, string | null>>'. Type 'RequestEvent<Partial<Record<string, string>>, string | null>' is missing the following properties from type 'Promise<RequestEvent<Partial<Record<string, string>>, string | null>>': then, catch, finally, [Symbol.toStringTag]ts(2345)...
Solution:
sveltekitCookies(async () => getRequestEvent()) seems to have resolved this for me

getFullOrganization function is throwing UNAUTHORIZED

Hey im using the function getFullOrganization to get the organization based on the slug and its throwing UNAUTHORIZED ```tsx import { authClient } from '@/lib/auth-client' import React from 'react'...

ERROR [Better Auth]: State not found undefined

I'm getting this error in this repo—the beta branch. I'm setting this SvelteKit project up to be deployed to Cloudflare. I implemented GitHub auth (the App way, not OAuth way). Everything works well, up until when GitHub redirects back to the app, then I get the page in the screenshot attached. @glassy had a similar issue, but his hint at the solution isn't quite clear to me: ``` As noted above, I forgot to include the query string when re-constructing the URL....
Solution:
No description

How to check if slug has spaces before the organization creation?

Hey all! I want to check if slug has spaces, if it has, return custom error so you can display error message on frontend "slug is invalid". I know about the beforeCreate and allowUserToCreateOrganization functions, but as far as I know, there is no way to return custom error message, to handle it on frontend.
Solution:
why not just validate client side before submission to the API endpoint

Next.js build failing

``` app/api/auth/[...all]/route.ts Type error: Route "app/api/auth/[...all]/route.ts" has an invalid export: "unknown" is not a valid GET return type: Expected "void | Response | Promise<void | Response>", got "unknown"....
Solution:
This ended up being I just needed to delete my node_modules

Google Provider prompt parameter type mismatch causes OAuth error

I'm encountering an issue with the Google OAuth provider configuration in better-auth. According to the documentation, to always get a refresh token, I should set prompt to "select_account+consent" as in documentation, but this causes a Google OAuth error. ``` socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string,...

How to use better auth in two frontend and one backend

I have a monorepo where I have two react router v7 frontend projects both using same Hono backend and better auth backend. The problem is when I sign in to my web frontend it also signs me in to my admin frontend project. how can I keep them separate?...

authClient.emailOtp.verifyEmail(), wrong endpoint "/email-verification"

Why does authClient.emailOtp.verifyEmail() keep sending to the regular endpoint /email-verification and NOT /email-otp/verify-email​ endpoint? I keep getting METHOD NOT ALLOWED, which makes sense as /email-verification is a GET, but I am sending a POST. Because I am expecting the authClient to hit /email-otp/verify-email, which is a POST....