Admin plugin

I am logged in but see
{
data: null,
error: { code: 'UNAUTHORIZED', status: 401, statusText: 'UNAUTHORIZED' }
}
{
data: null,
error: { code: 'UNAUTHORIZED', status: 401, statusText: 'UNAUTHORIZED' }
}
const users = await authClient.admin.listUsers({
query: {
limit: 10,
},
});
console.log(users);
const users = await authClient.admin.listUsers({
query: {
limit: 10,
},
});
console.log(users);
13 Replies
Ping
Ping2mo ago
Try passing headers to your listUsers function parameters
JohnyD
JohnyDOP2mo ago
const users = await authClient.admin.listUsers({
headers: headers(),
query: {
limit: 10,

},
});
const users = await authClient.admin.listUsers({
headers: headers(),
query: {
limit: 10,

},
});
Object literal may only specify known properties, and 'headers' does not exist in type 'Prettify<{ query: { limit?: string | number | undefined; offset?: string | number | undefined; sortBy?: string | undefined; searchValue?: string | undefined; searchField?: "email" | "name" | undefined; ... 4 more ...; filterOperator?: "eq" | ... 5 more ... | undefined; }; fetchOptions?: { ...; } | undefined; }>'
Ping
Ping2mo ago
Sorry, I mean in fetchOptions, then headers:
const users = await authClient.admin.listUsers({
fetchOptions: {
headers: await headers(),
},
query: {
limit: 10,
},
});
const users = await authClient.admin.listUsers({
fetchOptions: {
headers: await headers(),
},
query: {
limit: 10,
},
});
JohnyD
JohnyDOP2mo ago
Is it in the new version? Because the documentation doesn't say anything about it
No description
Ping
Ping2mo ago
It's a general rule of thumb across better-auth. Mostly only used on server auth API methods since the server doesn't know which user the api call is for, but there are cases occasionally on the client where it doesn't know how to pass the headers by itself when using the auth-client. Since the headers contains your cookies, which contains the user info. But yeah, you'll noticed every auth client method looks pretty much the same with the parameters. Sometimes it will require body, other times query (depends on the endpoint, whether it's POST or GET), but it will always contain the fetchOptions.
JohnyD
JohnyDOP2mo ago
the video does not transmit headers and everything works fine, is this because of this 'use client' ?
No description
Ping
Ping2mo ago
It's very possible. If your component isn't erroring, and you don't have "use client", then it's probably a RSC. Meaning it's being ran on the server - this would explain why it didn't know how to get the user's headers.
JohnyD
JohnyDOP2mo ago
one small question how do I expand type in db i have field organization: text("organization"),
No description
Ping
Ping2mo ago
I assume you already added the additional fields on the server better-auth instance. Have you added the inferAdditionalFields plugin on your client better-auth instance? https://www.better-auth.com/docs/concepts/typescript#inferring-additional-fields-on-client
TypeScript | Better Auth
Better Auth TypeScript integration.
JohnyD
JohnyDOP2mo ago
for export type User = typeof auth.$Infer.Session.user it worked There's a different type here and it didn't work
No description
Ping
Ping2mo ago
Didn't work as in it errored in run-time? or as in you saw a typescript error?
JohnyD
JohnyDOP2mo ago
No description
No description
Ping
Ping2mo ago
inferAdditionalFields will only work on any methods that is defaultly provided by the auth-client. So all other plugins can't infer those new types, including the admin plugin. Meaning that it's possible that the values you typed are valid, it's just typescript doesn't know that...

Did you find this page helpful?