403 User is not part of organization

I calling with authClient.useListOrganizations()all my organization but when I want to set one as active I get an 403 with message User is not a member of the organization. I checked in my db the users as well and he is part of organization. Do i miss something? my snippet:
"use client"
import { useState } from "react"
import { authClient } from "@/lib/auth-client"

export default function MinimalExample() {
const { data: organizations, isPending } = authClient.useListOrganizations()
const [isLoading, setIsLoading] = useState(false)

const handleSetFirstOrg = async () => {
if (!organizations || organizations.length === 0) return

setIsLoading(true)
try {
const firstOrg = organizations[0]
await authClient.organization.setActive({
organizationId: firstOrg.id,
organizationSlug: firstOrg.slug,
})
console.log("First organization set as active")
} catch (error) {
console.error("Error setting active organization:", error)
} finally {
setIsLoading(false)
}
}

if (isPending) return <div>Loading organizations...</div>

return (
<button
onClick={handleSetFirstOrg}
disabled={isLoading || !organizations?.length}
>
{isLoading ? "Setting..." : "Set First Organization Active"}
</button>
)
}
"use client"
import { useState } from "react"
import { authClient } from "@/lib/auth-client"

export default function MinimalExample() {
const { data: organizations, isPending } = authClient.useListOrganizations()
const [isLoading, setIsLoading] = useState(false)

const handleSetFirstOrg = async () => {
if (!organizations || organizations.length === 0) return

setIsLoading(true)
try {
const firstOrg = organizations[0]
await authClient.organization.setActive({
organizationId: firstOrg.id,
organizationSlug: firstOrg.slug,
})
console.log("First organization set as active")
} catch (error) {
console.error("Error setting active organization:", error)
} finally {
setIsLoading(false)
}
}

if (isPending) return <div>Loading organizations...</div>

return (
<button
onClick={handleSetFirstOrg}
disabled={isLoading || !organizations?.length}
>
{isLoading ? "Setting..." : "Set First Organization Active"}
</button>
)
}
6 Replies
Antoni
AntoniOP2mo ago
setActiveTeam works aswell fine.
discquist
discquist2mo ago
I'm seeing the same exact issue on my end. I can call the useListOrganizations hook but when i try to set the active org with the following i recieve a 403
const org = await authClient.organization.setActive({
organizationSlug: orgSlug,
});
const org = await authClient.organization.setActive({
organizationSlug: orgSlug,
});
I don't know where this regression happened but i rolled back to version 1.2.10 and now it works again as expected.
Antoni
AntoniOP2mo ago
@discquist found the issue, slug do not work anymore somehow, use the id and it works
discquist
discquist2mo ago
Ok thanks, that's too bad, since slugs could be used for better looking urls when using the active org for routing.. did you find any workaround for that?
Antoni
AntoniOP2mo ago
You could still use slug for the url and use from the session or the hook the id instead
discquist
discquist2mo ago
True! Thanks 👍

Did you find this page helpful?