$user
Updated on Aug 19, 2025 13 minutes to readThe User Plugin provides methods to manage application users, their roles, permissions, personal profiles, and avatars.
Methods
| Method | Description |
|---|---|
| can | Checks if a user has a specific permission. |
| create | Creates a new user account. |
| findById | Finds a user by ID. |
| update | Updates an existing user. |
| delete | Deletes a user by ID. |
| assignRoles | Assigns roles to a user. |
| revokeRoles | Revokes specific roles from a user. |
| revokeAllRoles | Revokes all roles from a user. |
| getAllRoles | Retrieves all roles assigned to a user. |
| block | Blocks a user account. |
| unblock | Unblocks a user account. |
| getProfile | Retrieves a user's profile information. |
| updateProfile | Updates a user's profile information. |
| updateAvatar | Sets or replaces a user's avatar. |
| deleteAvatar | Deletes a user's avatar. |
Methods Details
can()
• Type
(
id: string,
scriptAlias: E8ScriptAlias,
permission: string
) => boolean
• Details
Expects a user ID, a script alias, and a permission string.
Returns true if the user has the specified permission, otherwise false.
create()
• Type
(data: UserData, params?: UserParams) => User | false
• Details
Expects UserData
and optional UserParams (default: {sendWelcomeMessage: true, generateAccessToken: false}).
Returns the created User or false if creation failed.
findById()
• Type
(id: string) => User | false
• Details
Expects a user ID.
Returns the User or false if not found.
update()
• Type
(
id: string,
data: UserData,
params?: UserParams
) => User | false
• Details
Expects a user ID,
UserData,
and optional UserParams (default: {sendWelcomeMessage: false, generateAccessToken: false}).
Returns the updated User or false if update failed.
delete()
• Type
(id: string) => boolean
• Details
Expects a user ID.
Returns true if deletion was successful, otherwise false.
assignRoles()
• Type
(id: string, roles: string[]) => boolean
• Details
Expects a user ID and an array of role names.
Returns true if roles were successfully assigned, otherwise false.
revokeRoles()
• Type
(id: string, roles: string[]) => boolean
• Details
Expects a user ID and an array of role names.
Returns true if roles were successfully revoked, otherwise false.
revokeAllRoles()
• Type
(id: string) => boolean
• Details
Expects a user ID.
Returns true if all roles were revoked, otherwise false.
getAllRoles()
• Type
(id: string) => string[]
• Details
Expects a user ID.
Returns an array of role names assigned to the user.
block()
• Type
(id: string) => boolean
• Details
Expects a user ID.
Returns true if the account was successfully blocked, otherwise false.
unblock()
• Type
(id: string) => boolean
• Details
Expects a user ID.
Returns true if the account was successfully unblocked, otherwise false.
getProfile()
• Type
(id: string) => Profile | false
• Details
Expects a user ID.
Returns the Profile of the user or false if not found.
updateProfile()
• Type
(id: string, data: ProfileData) => Profile | false
• Details
Expects a user ID and ProfileData.
Returns the updated Profile or false if update failed.
updateAvatar()
• Type
(id: string, base64String: string) => boolean
• Details
Sets the user's avatar or replaces the existing one. Expects a user ID and a PNG image encoded as either a raw base64 string or a data URL starting with data:image/png;base64,.
Only PNG images are accepted. Source width and height must each be at least 100 pixels. There is no 1000-pixel upper limit for this method. Large PNG inputs, including 10 MB images, are supported subject to server request and memory limits; base64 increases the request size.
Images are processed using ImageResizer: the central square is selected and reduced to at most 200 × 200 pixels before saving. For example, an 800 × 600 image is cropped to the central 600 × 600 area and saved as 200 × 200. Smaller squares are not enlarged: a 150 × 100 source becomes 100 × 100. PNG format and transparency are preserved.
The method accepts two arguments. Crop position is always the center; there is no cropPosition option. To select a different area, crop the image before passing it to this method.
Returns true if the avatar was saved successfully, or false if the user was not found, the image data is empty or invalid, the format or dimensions are not allowed, or saving failed. Passing a value other than a string as base64String throws a TypeError.
• Example
// Set or replace an avatar using raw base64.
const updated = E8App.$user.updateAvatar(userId, base64String);
// A PNG data URL is also supported.
const updatedFromDataUrl = E8App.$user.updateAvatar(
userId,
"data:image/png;base64," + base64String
);
deleteAvatar()
• Type
(id: string) => boolean
• Details
Expects a user ID and deletes the user's avatar.
Returns true if deletion was successful, including when the user already has no avatar. Returns false if the user was not found or deletion failed.
Use this method to remove an avatar; passing an empty string to updateAvatar() is treated as invalid image data.
• Example
const deleted = E8App.$user.deleteAvatar(userId);