Skip to content

Commit 724a3fa

Browse files
committed
Update isSignedIn to check against initialized session
1 parent 4ac18aa commit 724a3fa

File tree

7 files changed

+18
-11
lines changed

7 files changed

+18
-11
lines changed

.changeset/nasty-mangos-live.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
'@clerk/vue': minor
99
---
1010

11-
Surface new `pending` session as an signed-in state, similarly as `active`
11+
Surface new `pending` session as a signed-in state

.changeset/proud-cycles-roll.md

+14
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,17 @@
44

55
- Initialize new `pending` session status as an signed-in state
66
- Deprecate `Clerk.client.activeSessions` in favor of `Clerk.client.signedInSessions`
7+
- Introduce `Clerk.isSignedIn` property as an explicit signed-in state check, instead of `!!Clerk.session` or `!!Clerk.user`:
8+
9+
```ts
10+
- if (Clerk.user) {
11+
+ if (Clerk.isSignedIn) {
12+
// Mount user button component
13+
document.getElementById('signed-in').innerHTML = `
14+
<div id="user-button"></div>
15+
`
16+
17+
const userbuttonDiv = document.getElementById('user-button')
18+
19+
clerk.mountUserButton(userbuttonDiv)
20+
}

packages/clerk-js/src/core/auth/cookies/clientUat.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const createClientUatCookie = (cookieSuffix: string): ClientUatCookieHand
3838
// '0' indicates the user is signed out
3939
let val = '0';
4040

41-
if (client && client.updatedAt && client.isSignedIn) {
41+
if (client && client.updatedAt && client.signedInSessions.length > 0) {
4242
// truncate timestamp to seconds, since this is a unix timestamp
4343
val = Math.floor(client.updatedAt.getTime() / 1000).toString();
4444
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export class Clerk implements ClerkInterface {
289289
}
290290

291291
get isSignedIn(): boolean {
292-
return !!this.client?.isSignedIn;
292+
return !!this.session;
293293
}
294294

295295
public constructor(key: string, options?: DomainOrProxyUrl) {

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

-4
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ export class Client extends BaseResource implements ClientResource {
118118
return this._basePostBypass({ body: params, path: this.path() + '/verify' });
119119
}
120120

121-
get isSignedIn() {
122-
return (this.signedInSessions ?? []).length > 0;
123-
}
124-
125121
fromJSON(data: ClientJSON | ClientJSONSnapshot | null): this {
126122
if (data) {
127123
this.id = data.id;

packages/types/src/clerk.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ export interface Clerk {
128128
isStandardBrowser: boolean | undefined;
129129

130130
/**
131-
* Indicates whether the current user has a valid, fully signed-in client session.
132-
* A session is considered valid when the user has successfully authenticated,
133-
* completed all required authentication factors, and resolved all pending tasks.
131+
* Indicates whether the current user has a valid signed-in client session
134132
*/
135133
isSignedIn: boolean;
136134

packages/types/src/client.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type { ClientJSONSnapshot } from './snapshots';
77
export interface ClientResource extends ClerkResource {
88
sessions: SessionResource[];
99
signedInSessions: (ActiveSessionResource | PendingSessionResource)[];
10-
isSignedIn: boolean;
1110
signUp: SignUpResource;
1211
signIn: SignInResource;
1312
isNew: () => boolean;

0 commit comments

Comments
 (0)