Skip to content

Commit ba1918d

Browse files
authored
feat(backend): Add last_sign_in_at filters to getUserList (#7704)
1 parent a630e1f commit ba1918d

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

.changeset/shaky-otters-care.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@clerk/backend': minor
3+
---
4+
5+
Add `lastSignInAtAfter` and `lastSignInAtBefore` filters to the Users API list and count endpoints.
6+
7+
These parameters are supported by `users.getUserList()` and are forwarded to `/v1/users` and `/v1/users/count` to filter users by last sign-in timestamp.

packages/backend/src/api/__tests__/factory.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,40 @@ describe('api.client', () => {
5959
expect(totalCount).toBe(2);
6060
});
6161

62+
it('executes users.getUserList() with last_sign_in_at filters', async () => {
63+
const afterTimestamp = 1640000000;
64+
const beforeTimestamp = 1700000000;
65+
66+
server.use(
67+
http.get(
68+
`https://api.clerk.test/v1/users`,
69+
validateHeaders(({ request }) => {
70+
const url = new URL(request.url);
71+
expect(url.searchParams.get('last_sign_in_at_after')).toBe(afterTimestamp.toString());
72+
expect(url.searchParams.get('last_sign_in_at_before')).toBe(beforeTimestamp.toString());
73+
return HttpResponse.json([userJson]);
74+
}),
75+
),
76+
http.get(
77+
`https://api.clerk.test/v1/users/count`,
78+
validateHeaders(({ request }) => {
79+
const url = new URL(request.url);
80+
expect(url.searchParams.get('last_sign_in_at_after')).toBe(afterTimestamp.toString());
81+
expect(url.searchParams.get('last_sign_in_at_before')).toBe(beforeTimestamp.toString());
82+
return HttpResponse.json({ object: 'total_count', total_count: 1 });
83+
}),
84+
),
85+
);
86+
87+
const { data, totalCount } = await apiClient.users.getUserList({
88+
lastSignInAtAfter: afterTimestamp,
89+
lastSignInAtBefore: beforeTimestamp,
90+
});
91+
92+
expect(data.length).toBe(1);
93+
expect(totalCount).toBe(1);
94+
});
95+
6296
it('executes a successful backend API request for a paginated response', async () => {
6397
server.use(
6498
http.get(

packages/backend/src/api/endpoints/UserApi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ type UserListParams = ClerkPaginationRequest<
4141
| 'last_sign_in_at'
4242
>;
4343
last_active_at_since?: number;
44+
lastSignInAtAfter?: number;
45+
lastSignInAtBefore?: number;
4446
organizationId?: string[];
4547
}
4648
>;

0 commit comments

Comments
 (0)