1+ import { createCookieHandler } from '@clerk/shared/cookie' ;
12import { setDevBrowserJWTInURL } from '@clerk/shared/devBrowser' ;
23import { is4xxError , isClerkAPIResponseError , isNetworkError } from '@clerk/shared/error' ;
34import type { Clerk , InstanceType } from '@clerk/types' ;
@@ -36,6 +37,7 @@ export class AuthCookieService {
3637 private poller : SessionCookiePoller | null = null ;
3738 private clientUat : ClientUatCookieHandler ;
3839 private sessionCookie : SessionCookieHandler ;
40+ private activeOrgCookie : ReturnType < typeof createCookieHandler > ;
3941 private devBrowser : DevBrowser ;
4042
4143 public static async create ( clerk : Clerk , fapiClient : FapiClient , instanceType : InstanceType ) {
@@ -62,6 +64,7 @@ export class AuthCookieService {
6264
6365 this . clientUat = createClientUatCookie ( cookieSuffix ) ;
6466 this . sessionCookie = createSessionCookie ( cookieSuffix ) ;
67+ this . activeOrgCookie = createCookieHandler ( 'clerk_active_org' ) ;
6568 this . devBrowser = createDevBrowser ( {
6669 frontendApi : clerk . frontendApi ,
6770 fapiClient,
@@ -191,20 +194,20 @@ export class AuthCookieService {
191194 * The below methods are used to determine whether or not an unfocused tab can be responsible
192195 * for setting the session cookie. A session cookie should only be set by a tab who's selected
193196 * organization matches the session's active organization. By storing the active organization
194- * ID in local storage , we can check the value across tabs. If a tab's organization ID does not
195- * match the value in local storage , it is not responsible for updating the session cookie.
197+ * ID in a cookie , we can check the value across tabs. If a tab's organization ID does not
198+ * match the value in the active org cookie , it is not responsible for updating the session cookie.
196199 */
197200
198201 public setActiveOrganizationInStorage ( ) {
199202 if ( this . clerk . organization ?. id ) {
200- localStorage . setItem ( 'clerk_active_org' , this . clerk . organization . id ) ;
203+ this . activeOrgCookie . set ( this . clerk . organization . id ) ;
201204 } else {
202- localStorage . removeItem ( 'clerk_active_org' ) ;
205+ this . activeOrgCookie . remove ( ) ;
203206 }
204207 }
205208
206209 private isCurrentOrganizationActive ( ) {
207- const activeOrganizationId = localStorage . getItem ( 'clerk_active_org' ) ;
210+ const activeOrganizationId = this . activeOrgCookie . get ( ) ;
208211
209212 if ( ! activeOrganizationId && ! this . clerk . organization ?. id ) {
210213 return true ;
0 commit comments