Anyway to access admin API from server?
I seem to be getting a 401 error on calling my auth API endpoints from my server
await auth.api.listUsers({
query: {
limit: 10,
},
})
admin:dev: [Error [APIError]: ] {
admin:dev: status: 'UNAUTHORIZED',
admin:dev: body: undefined,
admin:dev: headers: {},
admin:dev: statusCode: 401
admin:dev: }
3 Replies
If it helps at all, I'm attempting this in a monorepo setup where my services/better-auth are in a package, and I'm importing it into a nextjs page in an app
do you have a valid session or header ?
if you do have a valid header pass it an options with listUsers()
I don't, I'm trying to do it server side in payload, which has its own session management system - regardless though, there must be a way to just invoke the functions that run behind the scenes?
For example, what if I wanted to do some auth-related stuff in a worker?
I have a separate dashboard where I want to handle admin related stuff, including managing users, and without some hacky-work I'd struggle to not let standard users login while letting admins go through fine?
ah so i didn't realise auth.api requests were simply doing fetch requests, rather than using the functions themselves - thats what i was after