--- title: ServerUser subtitle: Reference for the ServerUser object enableTableOfContents: true tag: beta --- ## `ServerUser` The `ServerUser` object is used on the server side to represent a user. It includes all the functionality of a `CurrentUser` object, plus additional server-side functionality. ### Table of Contents ```typescript type ServerUser = // Inherits all functionality from CurrentUser & CurrentUser & { serverMetadata: Json; serverReadOnlyMetadata: Json; listTeams(): Promise; getTeam(id): Promise; createTeam(data): Promise; leaveTeam(team): Promise; getTeamProfile(team): Promise; hasPermission(scope, permissionId): Promise; getPermission(scope, permissionId[, options]): Promise; listPermissions(scope[, options]): Promise; listContactChannels(): Promise; createApiKey(options): Promise; listApiKeys(): Promise; }; ``` ### `serverUser.serverMetadata` The server metadata of the user as a `Json` object. This can be modified by the server. ```typescript declare const serverMetadata: Json; ``` ### `serverUser.serverReadOnlyMetadata` The server read-only metadata of the user as a `Json` object. This cannot be modified by the server. ```typescript declare const serverReadOnlyMetadata: Json; ``` ### `serverUser.listTeams()` Lists all teams the user is a member of. #### Returns `Promise`: The list of teams ```typescript declare function listTeams(): Promise; ``` ### `serverUser.getTeam(id)` Gets a team by ID. #### Parameters - `id`: The ID of the team #### Returns `Promise`: The team, or `null` if not found ```typescript declare function getTeam(id: string): Promise; ``` ### `serverUser.createTeam(data)` Creates a new team. #### Parameters - `data`: An object containing team data: - `name`: The name of the team - `displayName`: The display name of the team - `profileImageUrl`: The profile image URL of the team #### Returns `Promise`: The created team ```typescript declare function createTeam(data: { name: string; displayName?: string | null; profileImageUrl?: string | null; }): Promise; ``` ### `serverUser.leaveTeam(team)` Leaves a team. #### Parameters - `team`: The team to leave #### Returns `Promise` ```typescript declare function leaveTeam(team: ServerTeam): Promise; ``` ### `serverUser.getTeamProfile(team)` Gets the team profile for a team. #### Parameters - `team`: The team #### Returns `Promise`: The team profile ```typescript declare function getTeamProfile(team: ServerTeam): Promise; ``` ### `serverUser.hasPermission(scope, permissionId)` Checks if the user has a permission. #### Parameters - `scope`: The scope of the permission - `permissionId`: The ID of the permission #### Returns `Promise`: Whether the user has the permission ```typescript declare function hasPermission(scope: string, permissionId: string): Promise; ``` ### `serverUser.getPermission(scope, permissionId[, options])` Gets a permission. #### Parameters - `scope`: The scope of the permission - `permissionId`: The ID of the permission - `options`: An object containing options: - `or`: What to do if the permission is not found: - `"return-null"`: Return null (default) - `"throw"`: Throw an error #### Returns `Promise`: The permission, or `null` if not found ```typescript declare function getPermission( scope: string, permissionId: string, options?: { or?: 'return-null' | 'throw'; } ): Promise; ``` ### `serverUser.listPermissions(scope[, options])` Lists all permissions in a scope. #### Parameters - `scope`: The scope of the permissions - `options`: An object containing options: - `or`: What to do if no permissions are found: - `"return-empty"`: Return an empty array (default) - `"throw"`: Throw an error #### Returns `Promise`: The list of permissions ```typescript declare function listPermissions( scope: string, options?: { or?: 'return-empty' | 'throw'; } ): Promise; ``` ### `serverUser.listContactChannels()` Lists all contact channels for the user. #### Returns `Promise`: The list of contact channels ```typescript declare function listContactChannels(): Promise; ``` ### `serverUser.createApiKey(options)` Creates a new API key for the user. #### Parameters - `options`: An object containing options: - `name`: The name of the API key - `expiresAt`: The expiration date of the API key #### Returns `Promise`: The created API key ```typescript declare function createApiKey(options: { name: string; expiresAt?: Date; }): Promise; ``` ### `serverUser.listApiKeys()` Lists all API keys for the user. #### Returns `Promise`: The list of API keys ```typescript declare function listApiKeys(): Promise; ``` ## `CurrentServerUser` The `CurrentServerUser` object is used on the server side to represent the currently authenticated user. It includes all the functionality of a `ServerUser` object. ### Table of Contents ```typescript type CurrentServerUser = // Inherits all functionality from ServerUser ServerUser; ```