Skip to content

AdminAuthConfig

AdminAuthConfig = object

Defined in: packages/admin/src/types.ts:67

Auth adapter interface that bridges your app’s authentication to the admin panel.

The admin panel does not depend on @cfast/auth directly. Instead, you provide callback functions that the admin calls for authentication, role management, and impersonation. This keeps the admin decoupled from any specific auth library.

const auth: AdminAuthConfig = {
requireUser: async (request) => {
const session = await getSession(request);
return { user: session.user, grants: session.grants };
},
hasRole: (user, role) => user.roles.includes(role),
getRoles: (userId) => authInstance.getRoles(userId),
setRole: (userId, role) => authInstance.setRole(userId, role),
removeRole: (userId, role) => authInstance.removeRole(userId, role),
setRoles: (userId, roles) => authInstance.setRoles(userId, roles),
impersonate: (adminId, targetId, request) =>
authInstance.impersonate(adminId, targetId, request),
stopImpersonation: (request) =>
authInstance.stopImpersonation(request),
};

getRoles: (userId) => Promise<string[]>

Defined in: packages/admin/src/types.ts:75

Fetches all roles assigned to a user by ID. Used in user management views.

string

Promise<string[]>


hasRole: (user, role) => boolean

Defined in: packages/admin/src/types.ts:73

Checks whether the given user has a specific role. Used for the admin access guard.

AdminUser

string

boolean


optional impersonate: (adminId, targetId, request) => Promise<Response>

Defined in: packages/admin/src/types.ts:83

Starts an impersonation session. Should return a redirect Response that sets the impersonation cookie/session.

string

string

Request

Promise<Response>


removeRole: (userId, role) => Promise<void>

Defined in: packages/admin/src/types.ts:79

Removes a single role from a user. Called from the user detail role management UI.

string

string

Promise<void>


requireUser: (request) => Promise<{ grants: Grant[]; user: AdminUser; }>

Defined in: packages/admin/src/types.ts:69

Extracts the authenticated user and their permission grants from the request. Throws or redirects if unauthenticated.

Request

Promise<{ grants: Grant[]; user: AdminUser; }>


setRole: (userId, role) => Promise<void>

Defined in: packages/admin/src/types.ts:77

Assigns a single role to a user. Called from the user detail role management UI.

string

string

Promise<void>


setRoles: (userId, roles) => Promise<void>

Defined in: packages/admin/src/types.ts:81

Replaces all roles for a user with the given set. Used for bulk role assignment.

string

string[]

Promise<void>


optional stopImpersonation: (request) => Promise<Response>

Defined in: packages/admin/src/types.ts:89

Ends the current impersonation session. Should return a redirect Response that restores the admin session.

Request

Promise<Response>