Skip to content

Commit dd604c7

Browse files
perf: add filter to query only non expired sessions (#4288)
* perf: add check to make sure only non expired sessions are selected by default * remove console.logs * Create chatty-ants-bake.md * remove `expiresAt` from the publicData * remove internal from changelog --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 0a8d4bf commit dd604c7

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

.changeset/chatty-ants-bake.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@blitzjs/auth": patch
3+
"blitz": patch
4+
---
5+
6+
perf: add filter to select only non expired sessions

packages/blitz-auth/src/server/auth-plugin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ interface IsAuthorized {
2222
interface PrismaClientWithSession {
2323
session: {
2424
findFirst(args?: {where?: {handle?: SessionModel["handle"]}}): Promise<SessionModel | null>
25-
findMany(args?: {where?: {userId?: PublicData["userId"]}}): Promise<SessionModel[]>
25+
findMany(args?: {
26+
where?: {userId?: PublicData["userId"]; expiresAt?: {gt?: Date}}
27+
}): Promise<SessionModel[]>
2628
create(args: {
2729
data: SessionModel & {
2830
userId?: any
@@ -42,7 +44,7 @@ export const PrismaStorage = <Client extends PrismaClientWithSession>(
4244
): SessionConfigMethods => {
4345
return {
4446
getSession: (handle) => db.session.findFirst({where: {handle}}),
45-
getSessions: (userId) => db.session.findMany({where: {userId}}),
47+
getSessions: (userId) => db.session.findMany({where: {userId, expiresAt: {gt: new Date()}}}),
4648
createSession: (session) => {
4749
let user
4850
if (session.userId) {

0 commit comments

Comments
 (0)