User and OrgMemberInfo
User Object
The UserFromToken object contains information about the user and the organizations they are a member of.
It also has helper functions for checking org membership, roles, and permissions.
Properties
- Name
- userId
- Type
- string
- Description
- The user's unique ID 
 
- Name
- email
- Type
- string
- Description
- The user's email address 
 
- Name
- username
- Type
- string | undefined
- Description
- The user's username 
 
- Name
- firstName
- Type
- string | undefined
- Description
- The user's first name 
 
- Name
- lastName
- Type
- string | undefined
- Description
- The user's last name 
 
- Name
- legacyUserId
- Type
- string | undefined
- Description
- The user's legacy user ID. This is only set if you migrated from an external source. See Migrating Users for more information. 
 
- Name
- canCreateOrgs
- Type
- boolean
- Description
- Whether the user can create organizations 
 
- Name
- createdAt
- Type
- number
- Description
- The timestamp of when the user was created 
 
- Name
- emailConfirmed
- Type
- boolean
- Description
- If the user has confirmed their email 
 
- Name
- hasPassword
- Type
- boolean
- Description
- If the user has set a password to login 
 
- Name
- lastActiveAt
- Type
- number
- Description
- The timestamp of when the user was last active 
 
- Name
- mfaEnabled
- Type
- boolean
- Description
- Whether the user has enabled MFA 
 
- Name
- updatePasswordRequired
- Type
- boolean
- Description
- Whether the user is required to update their password 
 
- Name
- impersonatorUserId
- Type
- string | undefined
- Description
- If the user is being impersonated, this is the ID of the impersonator. See User Impersonation for more information. 
 
- Name
- properties
- Type
- object | undefined
- Description
- Additional properties set on the user. See User Properties for more information. 
 
- Name
- loginMethod
- Type
- object
- Description
- The method the user used to log in. Returns the Login Method Property object. 
 
- Name
- activeOrgId
- Type
- string | undefined
- Description
- The ID of the org set by the setActiveOrg function returned in the useUser hook. 
 
- Name
- getOrg
- Type
- (orgId: string) => OrgMemberInfo | undefined
- Description
- Returns the OrgMemberInfo for the given org ID 
 
- Name
- getOrgByName
- Type
- (orgName: string) => OrgMemberInfo | undefined
- Description
- Returns the OrgMemberInfo for the given org name 
 
- Name
- getOrgs
- Type
- () => OrgMemberInfo[]
- Description
- Returns all orgs that the user is a member of 
 
- Name
- isImpersonating
- Type
- () => boolean
- Description
- Whether the current user is being impersonated by someone else. See User Impersonation for more information. 
 
- Name
- getActiveOrgId
- Type
- () => string | undefined
- Description
- Returns the ID of the org set by the setActiveOrg function returned in the useUser hook. 
 
- Name
- getActiveOrg
- Type
- () => OrgMemberInfo
- Description
- Returns the OrgMemberInfo of the org set by the setActiveOrg function returned in the useUser hook. 
 
export async function getServerSideProps(context) {
    const user = await getUserFromServerSideProps(context)
    if (!user) {
        return { redirect: { destination: '/api/auth/login' } }
    }
    // this can be from anywhere
    const orgId = getOrgIdFromContext(context) 
    const isAdmin = user.getOrg(orgId)?.isRole("Admin")
    if (!isAdmin) {
        return { redirect: { destination: '/somewhere-else' } }
    }
    return {
        props: {},
    }
}
OrgMemberInfo Object
Contains information about the user's membership in an organization, such as their role and permissions. It's returned by the User object's getOrg, getOrgByName, and getOrgs functions.
Properties
- Name
- orgId
- Type
- string
- Description
- The ID of the organization 
 
- Name
- orgName
- Type
- string
- Description
- The name of the organization 
 
- Name
- urlSafeOrgName
- Type
- string
- Description
- The URL-safe name of the organization 
 
- Name
- userAssignedRole
- Type
- string
- Description
- The role of the user within this organization 
 
- Name
- userPermissions
- Type
- string[]
- Description
- The permissions of the user within this organization 
 
- Name
- orgMetadata
- Type
- object
- Description
- A JSON blob of the org's metadata 
 
- Name
- userInheritedRolesPlusCurrentRole
- Type
- object
- Description
- The role of the user within this organization plus each inherited role 
 
- Name
- isRole
- Type
- (role: string) => boolean
- Description
- Whether the user has the given role in this organization 
 
- Name
- isAtLeastRole
- Type
- (role: string) => boolean
- Description
- Whether the user has at least the given role in this organization 
 
- Name
- hasPermission
- Type
- (permission: string) => boolean
- Description
- Whether the user has the given permission in this organization 
 
- Name
- hasAllPermissions
- Type
- (permissions: string[]) => boolean
- Description
- Whether the user has all the given permissions in this organization 
 
- Name
- orgRoleStructure
- Type
- string
- Description
- The role structure set for your project. See multi roles per user for more information. 
 
- Name
- userAssignedAdditionalRoles
- Type
- string[]
- Description
- If using multiple roles per user, returns an array of roles that the user belongs to. Excludes the - userAssignedRole.
 
const org = user.getOrg("my-org-id")
const isAdmin = org?.isRole("Admin")
if (isAdmin) {
    console.log("User is an admin in", org.orgName)
}
