Next.js Pages 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 IDName
emailType string Description
The user's email addressName
usernameType string | undefined Description
The user's usernameName
firstNameType string | undefined Description
The user's first nameName
lastNameType string | undefined Description
The user's last nameName
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 organizationsName
createdAtType number Description
The timestamp of when the user was createdName
emailConfirmedType boolean Description
If the user has confirmed their emailName
hasPasswordType boolean Description
If the user has set a password to loginName
lastActiveAtType number Description
The timestamp of when the user was last activeName
mfaEnabledType boolean Description
Whether the user has enabled MFAName
updatePasswordRequiredType boolean Description
Whether the user is required to update their passwordName
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 IDName
getOrgByNameType (orgName: string) => OrgMemberInfo | undefined Description
Returns the OrgMemberInfo for the given org nameName
getOrgsType () => OrgMemberInfo[] Description
Returns all orgs that the user is a member ofName
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 organizationName
orgNameType string Description
The name of the organizationName
urlSafeOrgNameType string Description
The URL-safe name of the organizationName
userAssignedRoleType string Description
The role of the user within this organizationName
userPermissionsType string[] Description
The permissions of the user within this organizationName
orgMetadataType object Description
A JSON blob of the org's metadataName
userInheritedRolesPlusCurrentRoleType object Description
The role of the user within this organization plus each inherited roleName
isRoleType (role: string) => boolean Description
Whether the user has the given role in this organizationName
isAtLeastRoleType (role: string) => boolean Description
Whether the user has at least the given role in this organizationName
hasPermissionType (permission: string) => boolean Description
Whether the user has the given permission in this organizationName
hasAllPermissionsType (permissions: string[]) => boolean Description
Whether the user has all the given permissions in this organizationName
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)
}