Skip to content

Commit 37f4010

Browse files
committed
fix(clerk-js): Fixed bugs in setActive caused by new conditions on session
The `setActive` contains a few new conditions on the `session` param, given that in this case `session` can also be undefined (which is something we didn't have in the previous `setSession`). However, given that we use the current session if we don't pass a `session`, a lot of these checks can be removed. They were wrong in the first place, because they were also preventing the execution for `session === null` so the behaviour was different. https://www.notion.so/clerkdev/Add-ClerkJS-method-to-set-the-active-organization-2f551fafdbd14834a7b5519e87c6f254
1 parent 872c57d commit 37f4010

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

packages/clerk-js/src/core/clerk.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,7 @@ export default class Clerk implements ClerkInterface {
295295
}
296296
}
297297

298-
if (session) {
299-
this.#authService?.setAuthCookiesFromSession(session);
300-
}
298+
this.#authService?.setAuthCookiesFromSession(session);
301299

302300
// If this.session exists, then signout was triggered by the current tab
303301
// and should emit. Other tabs should not emit the same event again
@@ -308,7 +306,7 @@ export default class Clerk implements ClerkInterface {
308306
//1. setLastActiveSession to passed usersession (add a param).
309307
// Note that this will also update the session's active organization
310308
// id.
311-
if (session && typeof document != 'undefined' && document.hasFocus()) {
309+
if (typeof document != 'undefined' && document.hasFocus()) {
312310
await this.#touchLastActiveSession(session);
313311
}
314312

@@ -317,7 +315,7 @@ export default class Clerk implements ClerkInterface {
317315
// When undefined, neither SignedIn nor SignedOut renders, which avoids flickers or
318316
// automatic reloading when reloading shouldn't be happening.
319317
const beforeUnloadTracker = createBeforeUnloadTracker();
320-
if (session && beforeEmit) {
318+
if (beforeEmit) {
321319
beforeUnloadTracker.startTracking();
322320
this.session = undefined;
323321
this.organization = undefined;

0 commit comments

Comments
 (0)