@smplcty/auth 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/revoke-session.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { Queryable } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Revoke a session by
|
|
3
|
+
* Revoke a session by setting its `expires_at` to now.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* The session row is preserved for audit — you can distinguish
|
|
6
|
+
* "explicitly revoked" (expires_at close to created_at) from
|
|
7
|
+
* "expired naturally" (expires_at = created_at + ttl). The
|
|
8
|
+
* `session_authorization()` RLS function already checks
|
|
9
|
+
* `expires_at > now()`, so the session is locked out immediately.
|
|
10
|
+
*
|
|
11
|
+
* Idempotent: revoking a non-existent or already-expired session
|
|
12
|
+
* is not an error.
|
|
7
13
|
*
|
|
8
14
|
* @example
|
|
9
15
|
* ```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"revoke-session.d.ts","sourceRoot":"","sources":["../src/revoke-session.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"revoke-session.d.ts","sourceRoot":"","sources":["../src/revoke-session.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAS5C;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,aAAa,CACjC,EAAE,EAAE,SAAS,EACb,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAKf"}
|
package/dist/revoke-session.js
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { InvalidInputError } from './errors.js';
|
|
2
|
-
const
|
|
2
|
+
const EXPIRE_SESSION = `
|
|
3
|
+
UPDATE sessions
|
|
4
|
+
SET expires_at = now()
|
|
5
|
+
WHERE session_id = $1
|
|
6
|
+
AND (expires_at IS NULL OR expires_at > now())
|
|
7
|
+
`;
|
|
3
8
|
/**
|
|
4
|
-
* Revoke a session by
|
|
9
|
+
* Revoke a session by setting its `expires_at` to now.
|
|
5
10
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
11
|
+
* The session row is preserved for audit — you can distinguish
|
|
12
|
+
* "explicitly revoked" (expires_at close to created_at) from
|
|
13
|
+
* "expired naturally" (expires_at = created_at + ttl). The
|
|
14
|
+
* `session_authorization()` RLS function already checks
|
|
15
|
+
* `expires_at > now()`, so the session is locked out immediately.
|
|
16
|
+
*
|
|
17
|
+
* Idempotent: revoking a non-existent or already-expired session
|
|
18
|
+
* is not an error.
|
|
8
19
|
*
|
|
9
20
|
* @example
|
|
10
21
|
* ```ts
|
|
@@ -17,6 +28,6 @@ export async function revokeSession(db, sessionId) {
|
|
|
17
28
|
if (typeof sessionId !== 'string' || sessionId.length === 0) {
|
|
18
29
|
throw new InvalidInputError('sessionId must be a non-empty string');
|
|
19
30
|
}
|
|
20
|
-
await db.query(
|
|
31
|
+
await db.query(EXPIRE_SESSION, [sessionId]);
|
|
21
32
|
}
|
|
22
33
|
//# sourceMappingURL=revoke-session.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"revoke-session.js","sourceRoot":"","sources":["../src/revoke-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,MAAM,cAAc,GAAG,
|
|
1
|
+
{"version":3,"file":"revoke-session.js","sourceRoot":"","sources":["../src/revoke-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,MAAM,cAAc,GAAG;;;;;CAKtB,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,EAAa,EACb,SAAiB;IAEjB,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,iBAAiB,CAAC,sCAAsC,CAAC,CAAC;IACtE,CAAC;IACD,MAAM,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;AAC9C,CAAC"}
|
package/package.json
CHANGED