Team
This is a detailed reference for the Team
object. If you’re looking for a more high-level overview, please refer to our guide on teams.
On this page:
Team
A Team
object contains basic information and functions about a team, to the extent of which a member of the team would have access to it.
You can get Team
objects with the currentUser.useTeam(...)
or currentUser.useTeams()
functions. The created team will then inherit the permissions of that user; for example, the team.update(...)
function can only succeed if the user is allowed to make updates to the team.
Table of Contents
team.id
The team ID as a string
. This value is always unique.
Type Definition
team.displayName
The display name of the team as a string
.
Type Definition
team.profileImageUrl
The profile image URL of the team as a string
, or null
if no profile image is set.
Type Definition
team.clientMetadata
The client metadata of the team as a Json
object.
Type Definition
team.clientReadOnlyMetadata
The client read-only metadata of the team as a Json
object.
Type Definition
team.update(data)
Updates the team information.
Note that this operation requires the current user to have the $update_team
permission. If the user lacks this permission, an error will be thrown.
Parameters
The fields to update.
Returns
Promise<void>
Signature
Examples
team.inviteUser(options)
Sends an invitation email to a user to join the team.
Note that this operation requires the current user to have the $invite_members
permission. If the user lacks this permission, an error will be thrown.
An invitation email containing a magic link will be sent to the specified user. If the user has an existing account, they will be automatically added to the team upon clicking the link. For users without an account, the link will guide them through the sign-up process before adding them to the team.
Parameters
An object containing multiple properties.
Returns
Promise<void>
Signature
Examples
team.listUsers()
Gets a list of users in the team.
Note that this operation requires the current user to have the $read_members
permission. If the user lacks this permission, an error will be thrown.
Parameters
None.
Returns
Promise<TeamUser[]>
Signature
Examples
team.useUsers()
Signature
Examples
team.listInvitations()
Gets a list of invitations to the team.
Note that this operation requires the current user to have the $read_members
and $invite_members
permissions. If the user lacks this permission, an error will be thrown.
Parameters
None.
Returns
Promise<{ id: string, email: string, expiresAt: Date }[]>
Signature
Examples
team.useInvitations()
Functionally equivalent to listInvitations()
, but as a React hook.
Parameters
None.
Returns
{ id: string, email: string, expiresAt: Date }[]
Signature
Examples
ServerTeam
Like Team
, but with server permissions. Has full read and write access to everything.
Calling serverUser.getTeam(...)
and serverUser.listTeams()
will return ServerTeam
objects if the user is a ServerUser
. Alternatively, you can call stackServerApp.getTeam('team_id_123')
or stackServerApp.listTeams()
to query all teams of the project.
ServerTeam
extends the Team
object, providing additional functions and properties as detailed below. It’s important to note that while the Team
object’s functions may require specific user permissions, the corresponding functions in ServerTeam
can be executed without these permission checks. This allows for more flexible and unrestricted team management on the server side.
Table of Contents
serverTeam.createdAt
The date and time when the team was created.
Type Definition
serverTeam.serverMetadata
The server metadata of the team as a Json
object.
Type Definition
serverTeam.listUsers()
Gets a list of users in the team.
This is similar to the listUsers
method on the Team
object, but it returns ServerTeamUser
objects instead of TeamUser
objects and does not require any permissions.
Parameters
None.
Returns
Promise<ServerTeamUser[]>
Signature
Examples
serverTeam.useUsers()
This is the documentation for a React hook on a server type. This is uncommon, because server types are only available with server permissions and React Server Components do not use hooks. Ask yourself if you:
- Want to use this on the server, eg. in a React Server Component? Look for the respective function without the
use
prefix (eg.getUser
instead ofuseUser
). - Want to use this on the client, eg. in a React Client Component? Look at the documentation of the client type (eg.
CurrentUser
instead ofCurrentServerUser
). - Are an advanced user, building an internal tool, and confident that you are securing
SECRET_SERVER_KEY
correctly? Then this is for you.
Functionally equivalent to listUsers()
, but as a React hook.
serverTeam.addUser(userId)
Adds a user to the team directly without sending an invitation email.
Parameters
The ID of the user to add.
Returns
Promise<void>
Signature
Examples
serverTeam.removeUser(userId)
Removes a user from the team.
Parameters
The ID of the user to remove.
Returns
Promise<void>
Signature
Examples
serverTeam.delete()
Deletes the team.
Parameters
None.
Returns
Promise<void>