Organization Docs need update?

https://www.better-auth.com/docs/plugins/organization#members this need to be update? i tried to call this in nextjs
const data = await auth.api.listMembers({
query: {
organizationId: authData.session.activeOrganizationId,
limit: 100,
offset: 0,
sortBy: "createdAt",
sortDirection: "desc",
},
});
const data = await auth.api.listMembers({
query: {
organizationId: authData.session.activeOrganizationId,
limit: 100,
offset: 0,
sortBy: "createdAt",
sortDirection: "desc",
},
});
and i got this error
An error occurred in the Server Components render but no message was provided
An error occurred in the Server Components render but no message was provided
after i add headers
const org = await auth.api.listMembers({
headers: await headers(),
});
const org = await auth.api.listMembers({
headers: await headers(),
});
it works
Organization | Better Auth
The organization plugin allows you to manage your organization's members and teams.
No description
3 Replies
dun
dunOP5d ago
update: but i got this error but it intermitten.
⨯ [Error [APIError]: Failed to get session] {
status: 'INTERNAL_SERVER_ERROR',
body: [Object],
headers: {},
statusCode: 500,
digest: '3914836991'
}
GET /app/members 500 in 355ms
⨯ [Error [APIError]: Failed to get session] {
status: 'INTERNAL_SERVER_ERROR',
body: [Object],
headers: {},
statusCode: 500,
digest: '3914836991'
}
GET /app/members 500 in 355ms
Failed query: select "id", "expires_at", "token", "created_at", "updated_at", "ip_address", "user_agent", "user_id", "impersonated_by", "active_organization_id" from "session" where "session"."token" = $1
params: (this show the session_token from cookies)
Failed query: select "id", "expires_at", "token", "created_at", "updated_at", "ip_address", "user_agent", "user_id", "impersonated_by", "active_organization_id" from "session" where "session"."token" = $1
params: (this show the session_token from cookies)
this is my code :
const [org, invitations] = await Promise.all([
auth.api.listMembers({ headers: head }),
auth.api.listInvitations({ headers: head }),
]).catch(() => {
redirect("/");
});
const [org, invitations] = await Promise.all([
auth.api.listMembers({ headers: head }),
auth.api.listInvitations({ headers: head }),
]).catch(() => {
redirect("/");
});
after i restart the server. those error is gone
Ping
Ping4d ago
Can you share your auth config?
dun
dunOP3d ago
export const auth = betterAuth({
...authConfig,
...authFields,
emailAndPassword: {
enabled: true,
minPasswordLength: 8,
maxPasswordLength: 100,
requireEmailVerification: true,
sendResetPassword: async ({ user, url }) => {
sendResetPassword({ user, url });
},
},
emailVerification: {
sendOnSignUp: true,
sendOnSignIn: true,
autoSignInAfterVerification: true,
otpLength: 6,
expiresIn: 60 * 5, // 5 minutes
},
socialProviders: {
google: {
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
mapProfileToUser: () => ({
phoneNumber: "",
}),
},
},
session: {
cookieCache: {
enabled: true,
maxAge: 60, // 1 minute
},
},
plugins: [
emailOTP({
async sendVerificationOTP({ email, otp, type }) {
if (type === "email-verification") {
sendEmailVerification({ email, otp });
}
},
overrideDefaultEmailVerification: true,
}),
twoFactor(),
passkey(),
adminPlugin({
ac,
roles: {
admin,
user,
},
}),
authOrganization,
nextCookies(),
],
databaseHooks: {
session: {
create: {
before: async (userSession) => {
const membership = await getFirstOrganizationIdByUserId(
userSession.userId
);
return {
data: {
...userSession,
activeOrganizationId: membership?.organizationId,
},
};
},
},
},
},
});
export const auth = betterAuth({
...authConfig,
...authFields,
emailAndPassword: {
enabled: true,
minPasswordLength: 8,
maxPasswordLength: 100,
requireEmailVerification: true,
sendResetPassword: async ({ user, url }) => {
sendResetPassword({ user, url });
},
},
emailVerification: {
sendOnSignUp: true,
sendOnSignIn: true,
autoSignInAfterVerification: true,
otpLength: 6,
expiresIn: 60 * 5, // 5 minutes
},
socialProviders: {
google: {
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
mapProfileToUser: () => ({
phoneNumber: "",
}),
},
},
session: {
cookieCache: {
enabled: true,
maxAge: 60, // 1 minute
},
},
plugins: [
emailOTP({
async sendVerificationOTP({ email, otp, type }) {
if (type === "email-verification") {
sendEmailVerification({ email, otp });
}
},
overrideDefaultEmailVerification: true,
}),
twoFactor(),
passkey(),
adminPlugin({
ac,
roles: {
admin,
user,
},
}),
authOrganization,
nextCookies(),
],
databaseHooks: {
session: {
create: {
before: async (userSession) => {
const membership = await getFirstOrganizationIdByUserId(
userSession.userId
);
return {
data: {
...userSession,
activeOrganizationId: membership?.organizationId,
},
};
},
},
},
},
});
addtional fields for user
export const authFields = {
user: {
additionalFields: {
phoneNumber: {
type: "string",
required: true,
},
},
},
} satisfies
export const authFields = {
user: {
additionalFields: {
phoneNumber: {
type: "string",
required: true,
},
},
},
} satisfies
main config
export const authConfig = {
appName: "xxx",
trustedOrigins: [env.NEXT_PUBLIC_APP_URL],
advanced: {
cookiePrefix: env.NEXT_PUBLIC_COOKIE_PREFIX,
useSecureCookies: true,
},
database: drizzleAdapter(db, {
provider: "pg",
schema: {
...schema,
},
}),
} satisfies
export const authConfig = {
appName: "xxx",
trustedOrigins: [env.NEXT_PUBLIC_APP_URL],
advanced: {
cookiePrefix: env.NEXT_PUBLIC_COOKIE_PREFIX,
useSecureCookies: true,
},
database: drizzleAdapter(db, {
provider: "pg",
schema: {
...schema,
},
}),
} satisfies
organization
export const authOrganization = organization({
schema: {
organization: {
additionalFields: {
description: {
type: "string",
input: true,
required: false,
},
type: {
type: "string",
input: true,
required: true,
options: organizationTypeEnum,
},
status: {
type: "boolean",
input: true,
required: false,
defaultValue: true,
},
subscriptionPlan: {
type: "string",
input: true,
required: false,
options: ["free", "pro", "enterprise"],
},
},
},
},
sendInvitationEmail: async ({ email, organization, inviter, invitation }) => {
sendOrganizationInvitation({
email,
organization,
inviter: inviter.user,
invitation,
});
},
});
export const authOrganization = organization({
schema: {
organization: {
additionalFields: {
description: {
type: "string",
input: true,
required: false,
},
type: {
type: "string",
input: true,
required: true,
options: organizationTypeEnum,
},
status: {
type: "boolean",
input: true,
required: false,
defaultValue: true,
},
subscriptionPlan: {
type: "string",
input: true,
required: false,
options: ["free", "pro", "enterprise"],
},
},
},
},
sendInvitationEmail: async ({ email, organization, inviter, invitation }) => {
sendOrganizationInvitation({
email,
organization,
inviter: inviter.user,
invitation,
});
},
});
and i often got this error
GET /app 200 in 161ms
2025-10-17T17:16:02.273Z ERROR [Better Auth]: INTERNAL_SERVER_ERROR Error: Failed query: select "id", "expires_at", "token", "created_at", "updated_at", "ip_address", "user_agent", "user_id", "impersonated_by", "active_organization_id" from "session" where "session"."token" = $1
params: wTGazjNSzR1GtpF7IVJqOZCi9zQJJwUG
at async OrganizationPage (src/modules/organization/view/organization-page.tsx:22:30)
20 | export async function OrganizationPage() {
21 | const head = await headers();
> 22 | const [org, invitations] = await Promise.all([
| ^
23 | auth.api.listMembers({ headers: head }),
24 | auth.api.listInvitations({ headers: head }),
25 | ]).catch(() => { {
query: 'select "id", "expires_at", "token", "created_at", "updated_at", "ip_address", "user_agent", "user_id", "impersonated_by", "active_organization_id" from "session" where "session"."token" = $1',
params: [Array],
[cause]: [Error [PostgresError]: sorry, too many clients already] {
severity_local: 'FATAL',
severity: 'FATAL',
code: '53300',
file: 'proc.c',
line: '355',
routine: 'InitProcess'
}
}
GET /app/members 307 in 258ms
GET /app 200 in 161ms
2025-10-17T17:16:02.273Z ERROR [Better Auth]: INTERNAL_SERVER_ERROR Error: Failed query: select "id", "expires_at", "token", "created_at", "updated_at", "ip_address", "user_agent", "user_id", "impersonated_by", "active_organization_id" from "session" where "session"."token" = $1
params: wTGazjNSzR1GtpF7IVJqOZCi9zQJJwUG
at async OrganizationPage (src/modules/organization/view/organization-page.tsx:22:30)
20 | export async function OrganizationPage() {
21 | const head = await headers();
> 22 | const [org, invitations] = await Promise.all([
| ^
23 | auth.api.listMembers({ headers: head }),
24 | auth.api.listInvitations({ headers: head }),
25 | ]).catch(() => { {
query: 'select "id", "expires_at", "token", "created_at", "updated_at", "ip_address", "user_agent", "user_id", "impersonated_by", "active_organization_id" from "session" where "session"."token" = $1',
params: [Array],
[cause]: [Error [PostgresError]: sorry, too many clients already] {
severity_local: 'FATAL',
severity: 'FATAL',
code: '53300',
file: 'proc.c',
line: '355',
routine: 'InitProcess'
}
}
GET /app/members 307 in 258ms
any insight? @Ping

Did you find this page helpful?