User and Org Types
User Class
The User Class contains all the information about the current user. It is within the getUser returned from getUserOrRedirect.
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
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.
- Name
isRole
- Type
- (orgId: string, role: string) => boolean
- Description
A method to check if the user is the provided role in the provided org.
- Name
isAtLeastRole
- Type
- (orgId: string, role: string) => boolean
- Description
A method to check if the user is at least the provided role in the provided org.
- Name
hasPermission
- Type
- (orgId: string, permission: string) => boolean
- Description
A method to check if the user has the provided permission in the provided org.
- Name
hasAllPermissions
- Type
- (orgId: string, permission: string[]) => boolean
- Description
A method to check if the user has all the provided permissions in the provided org.
- Name
getUserProperty
- Type
- (key: string)
- Description
A method to retrieve the value of the provided property for the user. Returns undefined if no value is set.
export const loader = async ({ request, context }: LoaderFunctionArgs) => {
const user = await auth.getUser(request, context)
const orgId = // get from somewhere
const isAdmin = user?.getOrg(orgId)?.isRole("Admin")
if (!isAdmin) {
return redirect("/somewhere-else")
}
}
OrgMemberInfo Class
Contains information about the user's membership in an organization, such as their role and permissions. It's returned by the User Class functions getOrg, getOrgByName, and getOrgs.
Properties
- Name
orgId
- Type
- string
- Description
The ID of the organization
- Name
orgName
- Type
- string
- Description
The name of the organization
- 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
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
const org = user.getOrg("my-org-id")
const isAdmin = org?.isRole("Admin")
if (isAdmin) {
console.log("User is an admin in", org.orgName)
}