Skip to content

Update navigate-between-organizations.mdx #517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 12, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ You can now extract the `organizations` claim from ID tokens in the way you norm
For example, in React you could use:

```jsx
const {getClaim} = useKindeAuth();
console.log(getClaim("organizations", "id_token").value);
const { getClaim } = useKindeAuth()

getClaim('organizations', 'idToken').then((organizations) => {
console.log('value:', organizations?.value)
})
```
## Step 2: Build the switcher
Expand All @@ -76,18 +79,30 @@ To build a simple list of orgs, use something like the following React example.
In this example, we’ve also included a check to see if this is the current organization.
```jsx
const {getClaim, getOrganization} = useKindeAuth();
const { login, getClaim, getOrganization } = useKindeAuth()

const [orgs, setOrgs] = useState<{ id: string; name: string }[]>([])
const [currentOrgCode, setCurrentOrgCode] = useState<string | null>(null)

useEffect(() => {
getClaim('organizations', 'idToken').then((organizations) => {
setOrgs(organizations?.value ?? [])
})
getOrganization().then((org) => {
setCurrentOrgCode(org)
})
}, [getClaim, getOrganization])

<ul>
{getClaim("organizations", "idToken").value.map((item) => (
{orgs.map((item) => (
<li key={item.id}>
<button onClick={() => login({orgCode: item.id})} type="button">
<button onClick={() => login({ orgCode: item.id })} type='button'>
{item.name}
{getOrganization().orgCode === item.id ? " (Current)" : null}
{currentOrgCode === item.id ? ' (Current)' : null}
</button>
</li>
))}
</ul>;
</ul>
```
With some extra styling, a switcher might look something like this:
Expand Down