Nuxt's useFetch in Admin plugin?
Hello all!
I'm tryiong to build a small "users" dashboard in my Nuxt app, essentially by building a UI around the Admin plugin.
In the core Better Auth functions I could pass the
useFetch
function to make SSR work, I'm not seeing the same option in the Admin plugin however.
I'm pretty sure I'm not the first one doing this, but since I'm new to both Nuxt and Better Auth, it seems I'm the first one not knowing how to work around it. 😅
What is the formally correct way to use the Admin plugin with SSR in Nuxt? Should I just not use the client side api for the Admin plugin and create my own which I can use with useFetch
?4 Replies
Solution
With SSR you'd typically use the
auth.api
clientSo there is no isomorphic client for the Admin api?
I mean the
auth.api
only works on the server (right?), so I can't just use it in a Nuxt "Page". For the auth.api
client to work I'd need to wrap it in my own API:
server/api/users/index.get.ts
app/pages/dashboard/users.vue
Correct?The
auth.api
only works in the server yes. I'm not familiar with Nuxt but if a Page is rendered on the client then auth.api
will be inaccessible. The code you have provided above looks correct to me but again the docs say something about SSR and I am not 100% sure w.r.t the admin plugin with Nuxt
Try it out and see if it worksit works, it was just that I essentially need to dismiss the whole
authClient.admin
thing which seemed wrong to me.
Edit: well not the whole thing, I guess I can still use the actions (like "banUser", and the stuff which doesn't need to render on the server)