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.
Example
Section titled “Example”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),};Properties
Section titled “Properties”getRoles()
Section titled “getRoles()”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.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”Promise<string[]>
hasRole()
Section titled “hasRole()”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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
impersonate()?
Section titled “impersonate()?”
optionalimpersonate: (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.
Parameters
Section titled “Parameters”adminId
Section titled “adminId”string
targetId
Section titled “targetId”string
request
Section titled “request”Request
Returns
Section titled “Returns”Promise<Response>
removeRole()
Section titled “removeRole()”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.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
string
Returns
Section titled “Returns”Promise<void>
requireUser()
Section titled “requireUser()”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.
Parameters
Section titled “Parameters”request
Section titled “request”Request
Returns
Section titled “Returns”Promise<{ grants: Grant[]; user: AdminUser; }>
setRole()
Section titled “setRole()”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.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
string
Returns
Section titled “Returns”Promise<void>
setRoles()
Section titled “setRoles()”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.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
string[]
Returns
Section titled “Returns”Promise<void>
stopImpersonation()?
Section titled “stopImpersonation()?”
optionalstopImpersonation: (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.
Parameters
Section titled “Parameters”request
Section titled “request”Request
Returns
Section titled “Returns”Promise<Response>