Skip to content

Commit 0cae0c2

Browse files
committed
Improve compatibility with TypeORM v0.3
1 parent a2479d0 commit 0cae0c2

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ import { Bigint } from "typeorm-static";
8282

8383
Constructor receives an object. Following properties may be included:
8484

85-
- `cleanupLimit` For every new session, remove this many expired ones. Defaults to 0, in case you need to analyze sessions retrospectively.
85+
- `cleanupLimit` For every new session, remove this many expired ones (does not distinguish between users, so User A logging in can delete User B expired sessions). Defaults to 0, in case you need to analyze sessions retrospectively.
8686

8787
- `limitSubquery` Select and delete expired sessions in one query. Defaults to true, you can set false to make two queries, in case you want cleanupLimit but your MariaDB version doesn't support limit in a subquery.
8888

src/app/TypeormStore/TypeormStore.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,19 @@ export class TypeormStore extends Store {
134134
// @ts-ignore
135135
.then(async () => {
136136
try {
137+
// If a session with the given SID is already present (even deleted), renew it.
138+
// Else, create a new row/session.
137139
await this.repository.findOneOrFail({where: { id: sid }, withDeleted: true});
138140
await this.repository.update({
139141
destroyedAt: IsNull(),
140142
id: sid,
141143
} as any, {
142-
expiredAt: Date.now() + ttl * 1000,
144+
expiredAt: Date.now() + (ttl * 1000),
143145
json,
144146
});
145147
} catch (_) {
146148
await this.repository.insert({
147-
expiredAt: Date.now() + ttl * 1000,
149+
expiredAt: Date.now() + (ttl * 1000),
148150
id: sid,
149151
json,
150152
});
@@ -172,7 +174,9 @@ export class TypeormStore extends Store {
172174
public destroy = (sid: string | string[], fn?: (error?: any) => void) => {
173175
this.debug('DEL "%s"', sid);
174176

175-
Promise.all((Array.isArray(sid) ? sid : [sid]).map((x) => this.repository.softDelete({ id: x })))
177+
Promise.all((Array.isArray(sid) ? sid : [sid]).map((x) => {
178+
this.repository.softDelete({ id: x });
179+
}))
176180
.then(() => {
177181
if (fn) {
178182
fn();
@@ -195,7 +199,9 @@ export class TypeormStore extends Store {
195199

196200
if (sess?.cookie?.expires) {
197201
this.debug('Skip updating session "%s" expiration', sid);
198-
return;
202+
if (fn) {
203+
fn();
204+
}
199205
}
200206

201207
this.debug('EXPIRE "%s" ttl:%s', sid, ttl);

0 commit comments

Comments
 (0)