Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ next-env.d.ts

# tooling
/template
.env*
3 changes: 3 additions & 0 deletions src/core/modules/auth/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ export type AuthUser = {
providers: string[]
canChangeEmail: boolean
canChangePassword: boolean
// Ory organization id when the identity signed in via org SSO, else null.
organizationId: string | null
isSso: boolean
}
8 changes: 8 additions & 0 deletions src/core/server/auth/ory/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ export function fromKratosSessionIdentity(identity: {
external_id?: string | null
traits?: unknown
metadata_public?: unknown
organization_id?: string | null
}): AuthUser {
const traits = parseOryTraits(identity.traits, {
identityId: identity.id,
source: 'kratos_session',
})
const organizationId = identity.organization_id || null

return {
id: requireExternalId(identity),
identityId: identity.id,
Expand All @@ -85,6 +88,8 @@ export function fromKratosSessionIdentity(identity: {
providers: [],
canChangeEmail: false,
canChangePassword: false,
organizationId,
isSso: organizationId !== null,
}
}

Expand All @@ -105,6 +110,7 @@ export function fromOryIdentity(identity: Identity): AuthUser {
)
const hasOidcCredential = hasLinkedOidcCredential(identity.credentials?.oidc)
const canChangePassword = hasPasswordCredential && !hasOidcCredential
const organizationId = identity.organization_id || null

return {
id: requireExternalId(identity),
Expand All @@ -117,6 +123,8 @@ export function fromOryIdentity(identity: Identity): AuthUser {
// settings/verification flows instead of patching traits directly.
canChangeEmail: false,
canChangePassword,
organizationId,
isSso: organizationId !== null,
}
}

Expand Down
16 changes: 9 additions & 7 deletions src/features/dashboard/sidebar/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import DashboardSidebarMenuTeams from './menu-teams'
import { TeamAvatar } from './team-avatar'

export default function DashboardSidebarMenu() {
const { team } = useDashboard()
const { team, user } = useDashboard()
const { enabled: postHogEnabled } = useAppPostHogProvider()
const posthog = usePostHog()
const [createTeamOpen, setCreateTeamOpen] = useState(false)
Expand Down Expand Up @@ -83,12 +83,14 @@ export default function DashboardSidebarMenu() {
>
<DashboardSidebarMenuTeams />

<DropdownMenuItem
className="h-9 gap-2.5 [&_svg]:size-5 font-sans prose-body-highlight"
onSelect={() => setCreateTeamOpen(true)}
>
<AddIcon className="ml-0.5" /> Create new team
</DropdownMenuItem>
{!user.isSso && (
<DropdownMenuItem
className="h-9 gap-2.5 [&_svg]:size-5 font-sans prose-body-highlight"
onSelect={() => setCreateTeamOpen(true)}
>
<AddIcon className="ml-0.5" /> Create new team
</DropdownMenuItem>
)}

<DropdownMenuSeparator className="-mx-2" />

Expand Down
Loading