Skip to content

Commit ce67184

Browse files
committed
Revert "feat(clerk-js): send touch intent with session updates (#8101)"
This reverts commit 7e60d2b.
1 parent 4686538 commit ce67184

6 files changed

Lines changed: 18 additions & 90 deletions

File tree

.changeset/warm-touch-intent.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ describe('Clerk singleton', () => {
207207
const sut = new Clerk(productionPublishableKey);
208208
await sut.load();
209209
await sut.setActive({ session: mockSession as any as ActiveSessionResource });
210-
expect(mockSession.touch).toHaveBeenCalledWith({ intent: 'select_session' });
210+
expect(mockSession.touch).toHaveBeenCalled();
211211
});
212212

213213
describe('with `touchSession` set to false', () => {
@@ -218,7 +218,7 @@ describe('Clerk singleton', () => {
218218
const sut = new Clerk(productionPublishableKey);
219219
await sut.load({ touchSession: false });
220220
await sut.setActive({ session: mockSession as any as ActiveSessionResource });
221-
expect(mockSession.touch).toHaveBeenCalledWith({ intent: 'select_session' });
221+
expect(mockSession.touch).toHaveBeenCalled();
222222
});
223223
});
224224

@@ -233,7 +233,7 @@ describe('Clerk singleton', () => {
233233
const sut = new Clerk(productionPublishableKey);
234234
await sut.load();
235235
await sut.setActive({ session: mockSession as any as ActiveSessionResource });
236-
expect(mockSession.touch).toHaveBeenCalledWith({ intent: 'select_session' });
236+
expect(mockSession.touch).toHaveBeenCalled();
237237
});
238238

239239
it('sets __session and __client_uat cookie before calling __internal_onBeforeSetActive', async () => {
@@ -280,7 +280,7 @@ describe('Clerk singleton', () => {
280280
await sut.setActive({ organization: 'some-org-slug' });
281281

282282
await waitFor(() => {
283-
expect(mockSession2.touch).toHaveBeenCalledWith({ intent: 'select_org' });
283+
expect(mockSession2.touch).toHaveBeenCalled();
284284
expect(mockSession2.getToken).toHaveBeenCalled();
285285
expect((mockSession2 as any as ActiveSessionResource)?.lastActiveOrganizationId).toEqual('org_id');
286286
expect(sut.session).toMatchObject(mockSession2);
@@ -363,7 +363,7 @@ describe('Clerk singleton', () => {
363363
const sut = new Clerk(productionPublishableKey);
364364
await sut.load();
365365
await sut.setActive({ session: mockSession as any as PendingSessionResource, navigate });
366-
expect(mockSession.__internal_touch).toHaveBeenCalledWith({ intent: 'select_session' });
366+
expect(mockSession.__internal_touch).toHaveBeenCalled();
367367
expect(navigate).toHaveBeenCalled();
368368
});
369369

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ import type {
101101
Resources,
102102
SDKMetadata,
103103
SessionResource,
104-
SessionTouchParams,
105104
SetActiveParams,
106105
SignedInSessionResource,
107106
SignInProps,
@@ -1580,7 +1579,6 @@ export class Clerk implements ClerkInterface {
15801579
newSession?.currentTask &&
15811580
this.#options.taskUrls?.[newSession?.currentTask.key];
15821581
const shouldNavigate = !!(redirectUrl || taskUrl || setActiveNavigate);
1583-
const touchIntent: SessionTouchParams['intent'] = shouldSwitchOrganization ? 'select_org' : 'select_session';
15841582

15851583
//1. setLastActiveSession to passed user session (add a param).
15861584
// Note that this will also update the session's active organization
@@ -1601,7 +1599,7 @@ export class Clerk implements ClerkInterface {
16011599
if (shouldNavigate && newSession) {
16021600
try {
16031601
// __internal_touch does not call updateClient automatically
1604-
updatedClient = await newSession.__internal_touch({ intent: touchIntent });
1602+
updatedClient = await newSession.__internal_touch();
16051603
if (updatedClient) {
16061604
// We call updateClient manually, but without letting it emit
16071605
// It's important that the setTransitiveState call happens somewhat
@@ -1617,7 +1615,7 @@ export class Clerk implements ClerkInterface {
16171615
}
16181616
}
16191617
} else {
1620-
await this.#touchCurrentSession(newSession, touchIntent);
1618+
await this.#touchCurrentSession(newSession);
16211619
}
16221620
// If we do have the updatedClient, read from that, otherwise getSessionFromClient
16231621
// will fallback to this.client. This makes no difference now, but will if we
@@ -3152,7 +3150,7 @@ export class Clerk implements ClerkInterface {
31523150
this.#touchThrottledUntil = Date.now() + 5_000;
31533151

31543152
if (this.#options.touchSession) {
3155-
void this.#touchCurrentSession(this.session, 'focus');
3153+
void this.#touchCurrentSession(this.session);
31563154
}
31573155
});
31583156

@@ -3183,15 +3181,12 @@ export class Clerk implements ClerkInterface {
31833181
};
31843182

31853183
// TODO: Be more conservative about touches. Throttle, don't touch when only one user, etc
3186-
#touchCurrentSession = async (
3187-
session?: SignedInSessionResource | null,
3188-
intent: SessionTouchParams['intent'] = 'focus',
3189-
): Promise<void> => {
3184+
#touchCurrentSession = async (session?: SignedInSessionResource | null): Promise<void> => {
31903185
if (!session) {
31913186
return Promise.resolve();
31923187
}
31933188

3194-
await session.touch({ intent }).catch(e => {
3189+
await session.touch().catch(e => {
31953190
if (isUnauthenticatedError(e)) {
31963191
void this.handleUnauthenticated();
31973192
} else {

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import type {
2929
SessionResource,
3030
SessionStatus,
3131
SessionTask,
32-
SessionTouchParams,
3332
SessionVerificationJSON,
3433
SessionVerificationResource,
3534
SessionVerifyAttemptFirstFactorParams,
@@ -104,16 +103,14 @@ export class Session extends BaseResource implements SessionResource {
104103
};
105104

106105
private _touchPost = async (
107-
{ intent, skipUpdateClient }: { intent?: SessionTouchParams['intent']; skipUpdateClient: boolean } = {
108-
skipUpdateClient: false,
109-
},
106+
{ skipUpdateClient }: { skipUpdateClient: boolean } = { skipUpdateClient: false },
110107
): Promise<FapiResponseJSON<SessionJSON> | null> => {
111108
const json = await BaseResource._fetch<SessionJSON>(
112109
{
113110
method: 'POST',
114111
path: this.path('touch'),
115112
// any is how we type the body in the BaseMutateParams as well
116-
body: { active_organization_id: this.lastActiveOrganizationId, intent } as any,
113+
body: { active_organization_id: this.lastActiveOrganizationId } as any,
117114
},
118115
{ skipUpdateClient },
119116
);
@@ -124,8 +121,8 @@ export class Session extends BaseResource implements SessionResource {
124121
return json;
125122
};
126123

127-
touch = async ({ intent }: SessionTouchParams = {}): Promise<SessionResource> => {
128-
await this._touchPost({ intent, skipUpdateClient: false });
124+
touch = async (): Promise<SessionResource> => {
125+
await this._touchPost();
129126

130127
// _touchPost() will have updated `this` in-place
131128
// The post has potentially changed the session state, and so we need to ensure we emit the updated token that comes back in the response. This avoids potential issues where the session cookie is out of sync with the current session state.
@@ -146,8 +143,8 @@ export class Session extends BaseResource implements SessionResource {
146143
*
147144
* @internal
148145
*/
149-
__internal_touch = async ({ intent }: SessionTouchParams = {}): Promise<ClientResource | undefined> => {
150-
const json = await this._touchPost({ intent, skipUpdateClient: true });
146+
__internal_touch = async (): Promise<ClientResource | undefined> => {
147+
const json = await this._touchPost({ skipUpdateClient: true });
151148
return getClientResourceFromPayload(json);
152149
};
153150

packages/clerk-js/src/core/resources/__tests__/Session.test.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -798,37 +798,6 @@ describe('Session', () => {
798798
token: session.lastActiveToken,
799799
});
800800
});
801-
802-
it('passes touch intent in the request body', async () => {
803-
const sessionData = {
804-
status: 'active',
805-
id: 'session_1',
806-
object: 'session',
807-
user: createUser({}),
808-
last_active_organization_id: 'org_123',
809-
actor: null,
810-
created_at: new Date().getTime(),
811-
updated_at: new Date().getTime(),
812-
} as SessionJSON;
813-
const session = new Session(sessionData);
814-
815-
const requestSpy = BaseResource.clerk.getFapiClient().request as Mock;
816-
requestSpy.mockResolvedValue({
817-
payload: { response: sessionData },
818-
status: 200,
819-
});
820-
821-
await session.touch({ intent: 'focus' });
822-
823-
expect(requestSpy).toHaveBeenCalledWith(
824-
expect.objectContaining({
825-
body: { active_organization_id: 'org_123', intent: 'focus' },
826-
method: 'POST',
827-
path: '/client/sessions/session_1/touch',
828-
}),
829-
expect.anything(),
830-
);
831-
});
832801
});
833802

834803
describe('__internal_touch()', () => {
@@ -933,27 +902,6 @@ describe('Session', () => {
933902

934903
expect(session.lastActiveOrganizationId).toBe('org_456');
935904
});
936-
937-
it('passes touch intent in the request body', async () => {
938-
const session = new Session(mockSessionData);
939-
const requestSpy = BaseResource.clerk.getFapiClient().request as Mock;
940-
941-
requestSpy.mockResolvedValue({
942-
payload: { response: mockSessionData },
943-
status: 200,
944-
});
945-
946-
await session.__internal_touch({ intent: 'select_session' });
947-
948-
expect(requestSpy).toHaveBeenCalledWith(
949-
expect.objectContaining({
950-
body: { active_organization_id: 'org_123', intent: 'select_session' },
951-
method: 'POST',
952-
path: '/client/sessions/session_1/touch',
953-
}),
954-
expect.anything(),
955-
);
956-
});
957905
});
958906

959907
describe('isAuthorized()', () => {

packages/shared/src/types/session.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export interface SessionResource extends ClerkResource {
240240
*/
241241
end: () => Promise<SessionResource>;
242242
remove: () => Promise<SessionResource>;
243-
touch: (params?: SessionTouchParams) => Promise<SessionResource>;
243+
touch: () => Promise<SessionResource>;
244244
getToken: GetToken;
245245
checkAuthorization: CheckAuthorization;
246246
clearCache: () => void;
@@ -262,7 +262,7 @@ export interface SessionResource extends ClerkResource {
262262
) => Promise<SessionVerificationResource>;
263263
verifyWithPasskey: () => Promise<SessionVerificationResource>;
264264
__internal_toSnapshot: () => SessionJSONSnapshot;
265-
__internal_touch: (params?: SessionTouchParams) => Promise<ClientResource | undefined>;
265+
__internal_touch: () => Promise<ClientResource | undefined>;
266266
}
267267

268268
/**
@@ -322,12 +322,6 @@ export type SessionStatus =
322322
| 'revoked'
323323
| 'pending';
324324

325-
export type SessionTouchIntent = 'focus' | 'select_session' | 'select_org';
326-
327-
export type SessionTouchParams = {
328-
intent?: SessionTouchIntent;
329-
};
330-
331325
export interface PublicUserData {
332326
firstName: string | null;
333327
lastName: string | null;

0 commit comments

Comments
 (0)