This is a detailed reference for the CurrentUser object in the Next.js SDK.
You can call useUser() or stackServerApp.getUser() to get the CurrentUser object.
Table of Contents
id: string;
displayName: string | null;
primaryEmail: string | null;
primaryEmailVerified: boolean;
profileImageUrl: string | null;
signedUpAt: Date;
hasPassword: boolean;
clientMetadata: Json;
clientReadOnlyMetadata: Json;
selectedTeam: Team | null;
update(data): Promise<void>;
updatePassword(data): Promise<void>;
getAuthHeaders(): Promise<Record<string, string>>;
getAuthJson(): Promise<{"accessToken': string | null}>;
signOut([options]): Promise<void>;
delete(): Promise<void>;
getTeam(id): Promise<Team | null>;
⤷ useTeam(id): Team | null;
listTeams(): Promise<Team[]>;
⤷ useTeams(): Team[];
setSelectedTeam(team): Promise<void>;
createTeam(data): Promise<Team>;
leaveTeam(team): Promise<void>;
getTeamProfile(team): Promise<EditableTeamMemberProfile>;
⤷ useTeamProfile(team): EditableTeamMemberProfile;
hasPermission(scope, permissionId): Promise<boolean>;
getPermission(scope, permissionId[, options]): Promise<TeamPermission | null>;
⤷ usePermission(scope, permissionId[, options]): TeamPermission | null;
listPermissions(scope[, options]): Promise<TeamPermission[]>;
⤷ usePermissions(scope[, options]): TeamPermission[];
listContactChannels(): Promise<ContactChannel[]>;
⤷ useContactChannels(): ContactChannel[];
createApiKey(options): Promise<UserApiKeyFirstView>;
listApiKeys(): Promise<UserApiKey[]>;
⤷ useApiKeys(): UserApiKey[];
};
currentUser.id
The user ID as a string. This is the unique identifier of the user.
declare const id: string;currentUser.displayName
The display name of the user as a string or null if not set. The user can modify this value.
declare const displayName: string | null;currentUser.primaryEmail
The primary email of the user as a string or null. Note that this is not necessarily unique.
declare const primaryEmail: string | null;currentUser.primaryEmailVerified
A boolean indicating whether the primary email of the user is verified.
declare const primaryEmailVerified: boolean;currentUser.profileImageUrl
The profile image URL of the user as a string or null if no profile image is set.
declare const profileImageUrl: string | null;currentUser.signedUpAt
The date and time when the user signed up, as a Date.
declare const signedUpAt: Date;currentUser.hasPassword
A boolean indicating whether the user has a password set.
declare const hasPassword: boolean;currentUser.clientMetadata
The client metadata of the user as a Json object. This can be modified by the user.
declare const clientMetadata: Json;currentUser.clientReadOnlyMetadata
The client read-only metadata of the user as a Json object. This cannot be modified by the user.
declare const clientReadOnlyMetadata: Json;currentUser.selectedTeam
The currently selected team of the user as a Team object or null if no team is selected.
declare const selectedTeam: Team | null;currentUser.update(data)
Updates the user's profile.
Parameters
data: An object containing properties to update:displayName: The new display nameprofileImageUrl: The new profile image URLclientMetadata: The new client metadata
Returns
Promise<void>
declare function update(data: {
displayName?: string | null;
profileImageUrl?: string | null;
clientMetadata?: Json;
}): Promise<void>;currentUser.updatePassword(data)
Updates the user's password.
Parameters
data: An object containing properties to update:currentPassword: The current passwordnewPassword: The new password
Returns
Promise<void>
declare function updatePassword(data: {
currentPassword: string;
newPassword: string;
}): Promise<void>;currentUser.getAuthHeaders()
Gets the authentication headers for the user.
Returns
Promise<Record<string, string>>: The authentication headers.
declare function getAuthHeaders(): Promise<Record<string, string>>;currentUser.getAuthJson()
Gets the authentication JSON for the user.
Returns
Promise<{ accessToken: string | null }>: The authentication JSON.
declare function getAuthJson(): Promise<{ accessToken: string | null }>;currentUser.signOut([options])
Signs out the user.
Parameters
options: An object containing options:everywhere: Whether to sign out from all devices
Returns
Promise<void>
declare function signOut(options?: { everywhere?: boolean }): Promise<void>;currentUser.delete()
Deletes the user.
Returns
Promise<void>
declare function delete(): Promise<void>;currentUser.getTeam(id)
Gets a team by ID.
Parameters
id: The ID of the team
Returns
Promise<Team | null>: The team, or null if not found
declare function getTeam(id: string): Promise<Team | null>;currentUser.useTeam(id)
Gets a team by ID as a React hook.
Parameters
id: The ID of the team
Returns
Team | null: The team, or null if not found
declare function useTeam(id: string): Team | null;currentUser.listTeams()
Lists all teams the user is a member of.
Returns
Promise<Team[]>: The list of teams
declare function listTeams(): Promise<Team[]>;currentUser.useTeams()
Lists all teams the user is a member of as a React hook.
Returns
Team[]: The list of teams
declare function useTeams(): Team[];currentUser.setSelectedTeam(team)
Sets the selected team.
Parameters
team: The team to select
Returns
Promise<void>
declare function setSelectedTeam(team: Team): Promise<void>;currentUser.createTeam(data)
Creates a new team.
Parameters
data: An object containing team data:name: The name of the teamdisplayName: The display name of the teamprofileImageUrl: The profile image URL of the team
Returns
Promise<Team>: The created team
declare function createTeam(data: {
name: string;
displayName?: string | null;
profileImageUrl?: string | null;
}): Promise<Team>;currentUser.leaveTeam(team)
Leaves a team.
Parameters
team: The team to leave
Returns
Promise<void>
declare function leaveTeam(team: Team): Promise<void>;currentUser.getTeamProfile(team)
Gets the team profile for a team.
Parameters
team: The team
Returns
Promise<EditableTeamMemberProfile>: The team profile
declare function getTeamProfile(team: Team): Promise<EditableTeamMemberProfile>;currentUser.useTeamProfile(team)
Gets the team profile for a team as a React hook.
Parameters
team: The team
Returns
EditableTeamMemberProfile: The team profile
declare function useTeamProfile(team: Team): EditableTeamMemberProfile;currentUser.hasPermission(scope, permissionId)
Checks if the user has a permission.
Parameters
scope: The scope of the permissionpermissionId: The ID of the permission
Returns
Promise<boolean>: Whether the user has the permission
declare function hasPermission(scope: string, permissionId: string): Promise<boolean>;currentUser.getPermission(scope, permissionId[, options])
Gets a permission.
Parameters
scope: The scope of the permissionpermissionId: The ID of the permissionoptions: 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<TeamPermission | null>: The permission, or null if not found
declare function getPermission(
scope: string,
permissionId: string,
options?: {
or?: 'return-null' | 'throw';
}
): Promise<TeamPermission | null>;currentUser.usePermission(scope, permissionId[, options])
Gets a permission as a React hook.
Parameters
scope: The scope of the permissionpermissionId: The ID of the permissionoptions: An object containing options:or: What to do if the permission is not found:"return-null": Return null (default)"throw": Throw an error
Returns
TeamPermission | null: The permission, or null if not found
declare function usePermission(
scope: string,
permissionId: string,
options?: {
or?: 'return-null' | 'throw';
}
): TeamPermission | null;currentUser.listPermissions(scope[, options])
Lists all permissions in a scope.
Parameters
scope: The scope of the permissionsoptions: 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<TeamPermission[]>: The list of permissions
declare function listPermissions(
scope: string,
options?: {
or?: 'return-empty' | 'throw';
}
): Promise<TeamPermission[]>;currentUser.usePermissions(scope[, options])
Lists all permissions in a scope as a React hook.
Parameters
scope: The scope of the permissionsoptions: 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
TeamPermission[]: The list of permissions
declare function usePermissions(
scope: string,
options?: {
or?: 'return-empty' | 'throw';
}
): TeamPermission[];currentUser.listContactChannels()
Lists all contact channels for the user.
Returns
Promise<ContactChannel[]>: The list of contact channels
declare function listContactChannels(): Promise<ContactChannel[]>;currentUser.useContactChannels()
Lists all contact channels for the user as a React hook.
Returns
ContactChannel[]: The list of contact channels
declare function useContactChannels(): ContactChannel[];currentUser.createApiKey(options)
Creates a new API key for the user.
Parameters
options: An object containing options:name: The name of the API keyexpiresAt: The expiration date of the API key
Returns
Promise<UserApiKeyFirstView>: The created API key
declare function createApiKey(options: {
name: string;
expiresAt?: Date;
}): Promise<UserApiKeyFirstView>;currentUser.listApiKeys()
Lists all API keys for the user.
Returns
Promise<UserApiKey[]>: The list of API keys
declare function listApiKeys(): Promise<UserApiKey[]>;currentUser.useApiKeys()
Lists all API keys for the user as a React hook.
Returns
UserApiKey[]: The list of API keys
declare function useApiKeys(): UserApiKey[];