Better Auth & Nuxt 4
Given the new directory structure in Nuxt 4, what is the best and most secure way to set up Better Auth (https://better-auth.com) ? The information in the current docs applies more for the Nuxt 3 structure.
7 Replies
Hi @Dawit. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
I'm sorry, but the knowledge sources provided do not contain any information about integrating Better Auth (https://better-auth.com) with Nuxt 4 or its new directory structure. The available documentation covers authentication in Nuxt using the nuxt-auth-utils module, session management, and the new directory structure in Nuxt 4, but does not mention Better Auth specifically or provide integration steps for it.
If you are looking to implement authentication in Nuxt 4, the recommended and documented approach is to use nuxt-auth-utils, which supports session management, OAuth providers, and route protection, and is compatible with the new directory structure where your app code resides in the app/ directory and server code in the server/ directory. For more details, see the Sessions and Authentication guide and the Nuxt 4 directory structure documentation.
For Better Auth specifically, you may need to consult their official documentation or reach out to their support for Nuxt 4 compatibility and best practices.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@1000169766939529309> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@Dawit Did you end up using better-auth or nuxt-auth-utils?
Nothing new under the sun the server part stay in server folder and the client part in app folder just
I'm using better-auth. I'm pretty much following a similar approach to https://github.com/atinux/nuxthub-better-auth.
@Dawit I ended up using his example aswell.
It seems that the way it is described in betterauth documentation https://www.better-auth.com/docs/integrations/nuxt#ssr-usage is currently broken. There was a new GitHub Issue about it last week aswell https://github.com/better-auth/better-auth/issues/4722
GitHub
Nuxt SSR: useFetch integration causes session to return undefined a...
Is this suited for github? Yes, this is suited for github To Reproduce 1、Use Nuxt SSR with better-auth 2、Use const { data: session } = await authClient.useSession(useFetch) 3、Login with GitHub OAut...
That’s why I went with his example. It didn’t work for me with how the docs described it. Thanks for sharing that issue.