clerk-sveltekit icon indicating copy to clipboard operation
clerk-sveltekit copied to clipboard

How do I get the currently active organization?

Open matukosan opened this issue 1 year ago • 5 comments

I see there's SignedIn let:user. Is there something equivalent to get the currently active organization? Callbacks? Events? Exposed variables?

matukosan avatar Jul 02 '24 10:07 matukosan

I encountered the same situation right now: you should be able to receive the active organization through window.Clerk?.organization

mcmxcdev avatar Jul 16 '24 16:07 mcmxcdev

I encountered the same situation right now: you should be able to receive the active organization through window.Clerk?.organization

but how do I notice the organization changed? I need an event or reactive property...

matukosan avatar Jul 16 '24 18:07 matukosan

This might help you:

function handleClerkChange(event) {
    const user: UserResource = event.detail;
   // do stuff
}

onMount(() => {
    document.addEventListener('clerk-sveltekit:user', handleClerkChange);
    return () => {
        document.removeEventListener('clerk-sveltekit:user', handleClerkChange);
    };
});

spacycoder avatar Jul 18 '24 17:07 spacycoder

This PR in review but here's how to do it if it gets merged:

<script lang="ts">
	import { useClerkContext } from 'clerk-sveltekit/client'
      
        const { organization } = useClerkContext()

	$: console.log($organization)
</script>

wobsoriano avatar Jul 29 '24 14:07 wobsoriano

This might help you:

function handleClerkChange(event) {
    const user: UserResource = event.detail;
   // do stuff
}

onMount(() => {
    document.addEventListener('clerk-sveltekit:user', handleClerkChange);
    return () => {
        document.removeEventListener('clerk-sveltekit:user', handleClerkChange);
    };
});

gets current user object, but not organization

matukosan avatar Jul 31 '24 07:07 matukosan