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

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

const org = user.getOrg("my-org-id")
const isAdmin = org?.isRole("Admin")
if (isAdmin) {
    console.log("User is an admin in", org.orgName)
}