Next.js App Router - User and OrgMemberInfo - PropelAuth Docs
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
userIdType string
Description: The user's unique ID - Name
emailType string
Description: The user's email address - Name
usernameType string | undefined
Description: The user's username - Name
firstNameType string | undefined
Description: The user's first name - Name
lastNameType string | undefined
Description: The user's last name - Name
legacyUserIdType 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
canCreateOrgsType boolean
Description: Whether the user can create organizations - Name
createdAtType number
Description: The timestamp of when the user was created - Name
emailConfirmedType boolean
Description: If the user has confirmed their email - Name
hasPasswordType boolean
Description: If the user has set a password to login - Name
lastActiveAtType number
Description: The timestamp of when the user was last active - Name
mfaEnabledType boolean
Description: Whether the user has enabled MFA - Name
updatePasswordRequiredType boolean
Description: Whether the user is required to update their password - Name
impersonatorUserIdType string | undefined
Description: If the user is being impersonated, this is the ID of the impersonator. See User Impersonation for more information. - Name
propertiesType object | undefined
Description: Additional properties set on the user. See User Properties for more information. - Name
loginMethodType object
Description: The method the user used to log in. Returns the Login Method Property object. - Name
activeOrgIdType string | undefined
Description: The ID of the org set by the setActiveOrg function returned in the useUser hook. - Name
getOrgType (orgId: string) => OrgMemberInfo | undefined
Description: Returns the OrgMemberInfo for the given org ID - Name
getOrgByNameType (orgName: string) => OrgMemberInfo | undefined
Description: Returns the OrgMemberInfo for the given org name - Name
getOrgsType () => OrgMemberInfo[]
Description: Returns all orgs that the user is a member of - Name
isImpersonatingType () => boolean
Description: Whether the current user is being impersonated by someone else. See User Impersonation for more information. - Name
getActiveOrgIdType () => string | undefined
Description: Returns the ID of the org set by the setActiveOrg function returned in the useUser hook. - Name
getActiveOrgType () => 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
orgIdType string
Description: The ID of the organization - Name
orgNameType string
Description: The name of the organization - Name
urlSafeOrgNameType string
Description: The URL-safe name of the organization - Name
userAssignedRoleType string
Description: The role of the user within this organization - Name
userPermissionsType string[]
Description: The permissions of the user within this organization - Name
orgMetadataType object
Description: A JSON blob of the org's metadata - Name
userInheritedRolesPlusCurrentRoleType object
Description: The role of the user within this organization plus each inherited role - Name
isRoleType (role: string) => boolean
Description: Whether the user has the given role in this organization - Name
isAtLeastRoleType (role: string) => boolean
Description: Whether the user has at least the given role in this organization - Name
hasPermissionType (permission: string) => boolean
Description: Whether the user has the given permission in this organization - Name
hasAllPermissionsType (permissions: string[]) => boolean
Description: Whether the user has all the given permissions in this organization - Name
orgRoleStructureType string
Description: The role structure set for your project. See multi roles per user for more information. - Name
userAssignedAdditionalRolesType string[]
Description: If using multiple roles per user, returns an array of roles that the user belongs to. Excludes theuserAssignedRole.
const org = user.getOrg("my-org-id")
const isAdmin = org?.isRole("Admin")
if (isAdmin) {
console.log("User is an admin in", org.orgName)
}