We just shipped add-mcp: think npx skills but for MCPs. One command to install MCPs across all your editors and agents

Admin

Manage users, roles, bans, sessions, and impersonation

Beta

The Neon Auth with Better Auth is in Beta. Share your feedback on Discord or via the Neon Console.

Neon Auth is built on Better Auth and provides support for Admin plugin APIs through the Neon SDK. You do not need to manually install or configure the Better Auth Admin plugin.

The Admin plugin provides APIs to manage your users and their authentication state. It’s commonly used to build internal tooling (admin dashboards, support tools) that can:

  • Create and update users
  • Assign roles
  • Ban and unban users
  • List and revoke sessions
  • Impersonate a user for support/debugging

Prerequisites

  • A Neon project with Auth enabled

  • An existing user with an admin role to call Admin APIs.

    You can assign the admin role to a user through the Neon Console. Navigate to AuthUsers, open the three‑dot menu next to the user, and select Make admin.

    Assign admin role in Neon Console

Use Admin with SDK methods

You can call Admin plugin methods using the Neon SDK auth client.

If you haven’t set up Neon Auth yet, follow our Quick start guides to get started and create an authClient.

Create a user

Use the Admin APIs to create users on behalf of others (for example, back-office onboarding).

Parameters

View parameters
ParameterTypeRequiredNotes
emailstringEmail address for the new user
passwordstringPassword for the new user
namestringDisplay name
rolestring | string[] | undefinedOptional role(s) for the user (for example: user, admin)
dataRecord<string, any> | undefinedOptional custom fields
const { data, error } = await authClient.admin.createUser({
  email: 'user@email.com',
  password: 'secure-password',
  name: 'User Name',
  role: 'user',
  data: { customUserField: 'value' },
});

List users

List users with optional search, filtering, sorting, and pagination.

Parameters

View parameters
ParameterTypeRequiredNotes
searchValuestring | undefinedValue to search for
searchField'email' | 'name' | undefinedField to search in
searchOperator'contains' | 'starts_with' | 'ends_with' | undefinedSearch operator
limitnumber | string | undefinedMax users to return (page size)
offsetnumber | string | undefinedNumber of users to skip (pagination)
sortBystring | undefinedField to sort by
sortDirection'asc' | 'desc' | undefinedSort direction
filterFieldstring | undefinedField to filter by
filterValuestring | number | boolean | undefinedFilter value
filterOperator'eq' | 'ne' | 'lt' | 'lte' | 'gt' | 'gte' | undefinedFilter operator
const { data, error } = await authClient.admin.listUsers({
  query: {
    // Following parameters are optional
    searchValue: 'text to search',
    searchField: 'email',
    searchOperator: 'contains',
    limit: 10,
    offset: 0,
    sortBy: 'name',
    sortDirection: 'asc',
  },
});

Use filterField, filterValue, and filterOperator to further filter results (for example, by role etc)

The data object contains a list of users and pagination metadata:

{
  users: [/* array of user objects */],
  total: 100, // total number of users matching the query
  limit: 10,  // limit used in the query
  offset: 0   // offset used in the query
}

Use the total, limit, and offset values to implement pagination in your admin tooling.

Set a user role

Assign roles to control who can call admin operations.

Parameters

View parameters
ParameterTypeRequiredNotes
userIdstringThe user ID to update
rolestring | string[]Role(s) to apply (for example, admin)
const { error } = await authClient.admin.setRole({ userId: 'user-id', role: 'admin' });

Set a user password

Set or reset a user’s password.

View parameters
ParameterTypeRequiredNotes
userIdstringThe user ID to update
newPasswordstringThe new password
const { error } = await authClient.admin.setUserPassword({
  userId: 'user-id',
  newPassword: 'new-secure-password',
});

Update user details

Update user information such as email, name, and custom fields.

View parameters
ParameterTypeRequiredNotes
userIdstringThe user ID to update
dataRecord<string, any>Fields to update (email, name, custom fields)
const { error } = await authClient.admin.updateUser({
  userId: 'user-id',
  data: { name: 'New Name' },
});

Ban user

Banning prevents sign-in for a user. You can optionally provide a reason and expiration for the ban.

View parameters
ParameterTypeRequiredNotes
userIdstringThe user ID to ban
banReasonstring | undefinedReason for the ban
banExpiresInnumber | undefinedDuration in seconds until the ban expires. If not provided, the ban does not expire
const { error } = await authClient.admin.banUser({
  userId: 'user-id',
  banReason: 'Policy violation',
  // banExpiresIn: 60 * 60 * 24, // optional (seconds)
});

Unban user

Unban a previously banned user.

View parameters
ParameterTypeRequiredNotes
userIdstringThe user ID to unban
const { error } = await authClient.admin.unbanUser({ userId: 'user-id' });

Manage sessions

Use session APIs to view active sessions and revoke them.

List sessions

View parameters
ParameterTypeRequiredNotes
userIdstringThe user ID whose sessions you want to list
const { data, error } = await authClient.admin.listUserSessions({ userId: 'user-id' });

Revoke a session

View parameters
ParameterTypeRequiredNotes
sessionTokenstringThe session token to revoke
const { error } = await authClient.admin.revokeUserSession({ sessionToken: 'session-token' });

Revoke all sessions

View parameters
ParameterTypeRequiredNotes
userIdstringThe user ID whose sessions you want to revoke
const { error } = await authClient.admin.revokeUserSessions({ userId: 'user-id' });

Impersonate a user

Impersonation creates a session that behaves like the target user (useful for support and debugging).

View parameters
ParameterTypeRequiredNotes
userIdstringThe user ID to impersonate
const { data, error } = await authClient.admin.impersonateUser({ userId: 'user-id' });

Stop impersonation

Stop an active impersonation session.

View parameters

This method does not take any parameters.

const { error } = await authClient.admin.stopImpersonating();

Limitations

  • Admin operations require an authenticated session (HTTP-only cookies). This means your admin tooling must run on the same site that can send those cookies to the Neon Auth API.
  • Impersonation sessions are intentionally time‑limited, lasting for the duration of the active browser session or up to 1 hour. This design helps minimize security risks associated with long‑lived impersonation.

Need help?

Join our Discord Server to ask questions or see what others are doing with Neon. For paid plan support options, see Support.

Last updated on

Was this page helpful?