@boopkit/cap-users 0.4.2 → 0.4.3
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/capability.json +3 -3
- package/dist/auth-middleware.d.ts +12 -6
- package/dist/auth-middleware.d.ts.map +1 -1
- package/dist/auth-middleware.js +45 -21
- package/dist/auth-middleware.js.map +1 -1
- package/package.json +1 -1
- package/scaffold/src/controllers/auth.ts +1 -1
- package/scaffold/src/middleware/auth.ts +2 -2
package/capability.json
CHANGED
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
"phase": "imports",
|
|
44
|
-
"code": "import {
|
|
44
|
+
"code": "import { resolveVisitor, addAuthContext, authRoutes } from './middleware/auth';",
|
|
45
45
|
"description": "auth middleware and routes — session resolution, trust context, signup/login/logout"
|
|
46
46
|
},
|
|
47
47
|
{
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
{
|
|
59
59
|
"phase": "preRoutes",
|
|
60
60
|
"order": 15,
|
|
61
|
-
"code": "app.use(
|
|
62
|
-
"description": "resolve
|
|
61
|
+
"code": "app.use(resolveVisitor);",
|
|
62
|
+
"description": "resolve user from auth_id/visitor_id cookie if present (no user is created for anonymous traffic — write paths must call getOrCreateUser)"
|
|
63
63
|
},
|
|
64
64
|
{
|
|
65
65
|
"phase": "preRoutes",
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Auth middleware factories for Express.
|
|
3
3
|
*
|
|
4
|
-
* Provides
|
|
5
|
-
* - `
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Provides:
|
|
5
|
+
* - `resolveVisitor` — resolves req.user/sessionToken/visitorToken from auth_id/visitor_id
|
|
6
|
+
* cookies if present. Never creates a user or sets cookies. If no cookie resolves,
|
|
7
|
+
* req.user stays undefined so anonymous traffic does not mint user records.
|
|
8
|
+
* - `getOrCreateUser` — helper for write paths (waitlist capture, signup, onboarding).
|
|
9
|
+
* Mints a user + visitor identity + session token and sets cookies on first call.
|
|
10
|
+
* Idempotent: if resolveVisitor already populated req, returns the existing user.
|
|
11
|
+
* - `requireAuth` — gates routes by trust tier, redirects web / 401s API.
|
|
12
|
+
* - `addAuthContext` — populates res.locals.auth for view templates.
|
|
8
13
|
*/
|
|
9
14
|
import type { Request, Response, NextFunction } from 'express';
|
|
10
15
|
import type { AuthService } from './auth-service.js';
|
|
11
16
|
import type { IdentityService } from './identity-service.js';
|
|
12
17
|
import type { UserService } from './user-service.js';
|
|
13
|
-
import type { BaseUserInfo, TrustTier } from './types.js';
|
|
18
|
+
import type { BaseUserInfo, TrustTier, User } from './types.js';
|
|
14
19
|
/** Dependencies injected into createAuthMiddleware. */
|
|
15
20
|
export interface AuthMiddlewareDeps {
|
|
16
21
|
authService: AuthService;
|
|
@@ -39,7 +44,8 @@ export interface AuthLocals {
|
|
|
39
44
|
}
|
|
40
45
|
/** The middleware functions returned by createAuthMiddleware. */
|
|
41
46
|
export interface AuthMiddleware {
|
|
42
|
-
|
|
47
|
+
resolveVisitor: (req: Request, res: Response, next: NextFunction) => void;
|
|
48
|
+
getOrCreateUser: (req: Request, res: Response) => Promise<User<BaseUserInfo>>;
|
|
43
49
|
requireAuth: (requiredTrust?: TrustTier) => (req: Request, res: Response, next: NextFunction) => void;
|
|
44
50
|
addAuthContext: (req: Request, res: Response, next: NextFunction) => void;
|
|
45
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-middleware.d.ts","sourceRoot":"","sources":["../src/auth-middleware.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"auth-middleware.d.ts","sourceRoot":"","sources":["../src/auth-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,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AAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;IACtG,cAAc,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;CAC3E;AASD;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,kBAAkB,EACxB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,cAAc,CA0KhB"}
|
package/dist/auth-middleware.js
CHANGED
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Auth middleware factories for Express.
|
|
4
4
|
*
|
|
5
|
-
* Provides
|
|
6
|
-
* - `
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Provides:
|
|
6
|
+
* - `resolveVisitor` — resolves req.user/sessionToken/visitorToken from auth_id/visitor_id
|
|
7
|
+
* cookies if present. Never creates a user or sets cookies. If no cookie resolves,
|
|
8
|
+
* req.user stays undefined so anonymous traffic does not mint user records.
|
|
9
|
+
* - `getOrCreateUser` — helper for write paths (waitlist capture, signup, onboarding).
|
|
10
|
+
* Mints a user + visitor identity + session token and sets cookies on first call.
|
|
11
|
+
* Idempotent: if resolveVisitor already populated req, returns the existing user.
|
|
12
|
+
* - `requireAuth` — gates routes by trust tier, redirects web / 401s API.
|
|
13
|
+
* - `addAuthContext` — populates res.locals.auth for view templates.
|
|
9
14
|
*/
|
|
10
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
16
|
exports.createAuthMiddleware = createAuthMiddleware;
|
|
@@ -27,19 +32,19 @@ function createAuthMiddleware(deps, options) {
|
|
|
27
32
|
const visitorCookieMaxAge = options?.visitorCookieMaxAge ?? TEN_YEARS_MS;
|
|
28
33
|
const loginPath = options?.loginPath ?? '/login';
|
|
29
34
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
35
|
+
* resolveVisitor — read-only resolver. Populates req.user, req.sessionToken, and
|
|
36
|
+
* req.visitorToken from the auth_id/visitor_id cookies when present. Never creates
|
|
37
|
+
* a user or writes cookies. Anonymous traffic (no resolvable cookie) passes through
|
|
38
|
+
* with req.user undefined. Write paths that need a persisted user should call
|
|
39
|
+
* getOrCreateUser explicitly.
|
|
34
40
|
*/
|
|
35
|
-
function
|
|
36
|
-
|
|
41
|
+
function resolveVisitor(req, res, next) {
|
|
42
|
+
resolveFromCookies(req).then(() => next()).catch(next);
|
|
37
43
|
}
|
|
38
|
-
async function
|
|
44
|
+
async function resolveFromCookies(req) {
|
|
39
45
|
let user;
|
|
40
46
|
let sessionToken;
|
|
41
47
|
let visitorToken;
|
|
42
|
-
// --- Phase 1: Resolve user from existing cookies ---
|
|
43
48
|
// Try auth_id first (most authoritative for current session)
|
|
44
49
|
const rawAuthToken = req.cookies?.[cookieName];
|
|
45
50
|
if (rawAuthToken) {
|
|
@@ -60,22 +65,36 @@ function createAuthMiddleware(deps, options) {
|
|
|
60
65
|
if (!user) {
|
|
61
66
|
user = await userService.findById(identity.userId) ?? undefined;
|
|
62
67
|
}
|
|
63
|
-
|
|
68
|
+
if (user) {
|
|
69
|
+
visitorToken = rawVisitorToken;
|
|
70
|
+
}
|
|
71
|
+
// If the visitor identity resolves but to a different user than auth_id
|
|
72
|
+
// resolved, we keep the auth_id user; the visitor cookie is treated as stale
|
|
73
|
+
// and a fresh one will be minted on the next getOrCreateUser call.
|
|
64
74
|
}
|
|
65
|
-
// If identity not found, visitor cookie is stale — will be replaced below
|
|
66
75
|
}
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
req.user = user;
|
|
77
|
+
req.sessionToken = sessionToken;
|
|
78
|
+
req.visitorToken = visitorToken;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* getOrCreateUser — call from write paths that need a persisted user (waitlist
|
|
82
|
+
* capture, signup, onboarding). Mints a user + visitor identity + session token
|
|
83
|
+
* and sets the auth_id/visitor_id cookies. Idempotent: re-uses whatever resolveVisitor
|
|
84
|
+
* already populated on req, and only mints the pieces that are missing.
|
|
85
|
+
*/
|
|
86
|
+
async function getOrCreateUser(req, res) {
|
|
87
|
+
let user = req.user;
|
|
88
|
+
let sessionToken = req.sessionToken;
|
|
89
|
+
let visitorToken = req.visitorToken;
|
|
69
90
|
if (!user) {
|
|
70
91
|
user = await userService.create({ type: 'user' });
|
|
71
92
|
}
|
|
72
|
-
// Ensure visitor_id cookie exists
|
|
73
93
|
if (!visitorToken) {
|
|
74
94
|
visitorToken = (0, auth_service_js_1.generateToken)();
|
|
75
95
|
await identityService.create(user.id, 'cookie', (0, auth_service_js_1.hashToken)(visitorToken));
|
|
76
96
|
res.cookie(visitorCookieName, visitorToken, { maxAge: visitorCookieMaxAge, httpOnly: true });
|
|
77
97
|
}
|
|
78
|
-
// Ensure auth_id session cookie exists
|
|
79
98
|
if (!sessionToken) {
|
|
80
99
|
sessionToken = await authService.generateSessionToken(user.id);
|
|
81
100
|
res.cookie(cookieName, sessionToken, { maxAge: cookieMaxAge, httpOnly: true });
|
|
@@ -83,6 +102,7 @@ function createAuthMiddleware(deps, options) {
|
|
|
83
102
|
req.user = user;
|
|
84
103
|
req.sessionToken = sessionToken;
|
|
85
104
|
req.visitorToken = visitorToken;
|
|
105
|
+
return user;
|
|
86
106
|
}
|
|
87
107
|
/**
|
|
88
108
|
* requireAuth — middleware factory. Checks trust tier for the current session.
|
|
@@ -128,11 +148,14 @@ function createAuthMiddleware(deps, options) {
|
|
|
128
148
|
async function populateAuthContext(req, res) {
|
|
129
149
|
const user = req.user;
|
|
130
150
|
const sessionToken = req.sessionToken;
|
|
131
|
-
if (!user
|
|
151
|
+
if (!user) {
|
|
132
152
|
res.locals.auth = { trustTier: null, userName: null, userEmail: null, userInitial: null };
|
|
133
153
|
return;
|
|
134
154
|
}
|
|
135
|
-
|
|
155
|
+
// A resolved user is at minimum 'recognized' (we identified them by cookie). The
|
|
156
|
+
// session token's grant can raise that to 'authenticated' or 'verified' when present.
|
|
157
|
+
const grantedTier = sessionToken ? await authService.getTrustTier(user.id, sessionToken) : null;
|
|
158
|
+
const trustTier = grantedTier ?? 'recognized';
|
|
136
159
|
const name = user.info.name ?? null;
|
|
137
160
|
const email = user.info.email ?? null;
|
|
138
161
|
const userInitial = (name ?? email ?? '?')[0].toUpperCase();
|
|
@@ -144,7 +167,8 @@ function createAuthMiddleware(deps, options) {
|
|
|
144
167
|
};
|
|
145
168
|
}
|
|
146
169
|
return {
|
|
147
|
-
|
|
170
|
+
resolveVisitor,
|
|
171
|
+
getOrCreateUser,
|
|
148
172
|
requireAuth,
|
|
149
173
|
addAuthContext,
|
|
150
174
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-middleware.js","sourceRoot":"","sources":["../src/auth-middleware.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"auth-middleware.js","sourceRoot":"","sources":["../src/auth-middleware.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AA8DH,oDA6KC;AAvOD,4CAA+C;AAC/C,uDAA6D;AAM7D,MAAM,MAAM,GAAG,IAAA,qBAAY,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAyC7C,kCAAkC;AAElC,MAAM,WAAW,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC9C,MAAM,YAAY,GAAG,EAAE,GAAG,WAAW,CAAC;AAEtC,gCAAgC;AAEhC;;GAEG;AACH,SAAgB,oBAAoB,CAClC,IAAwB,EACxB,OAA+B;IAE/B,MAAM,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IAC3D,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,SAAS,CAAC;IACpD,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,WAAW,CAAC;IAC1D,MAAM,iBAAiB,GAAG,OAAO,EAAE,iBAAiB,IAAI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CAAC,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAChG,MAAM,SAAS,GAAc,WAAW,IAAI,YAAY,CAAC;QACzD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC;QACpC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC;QACtC,MAAM,WAAW,GAAG,CAAC,IAAI,IAAI,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAE5D,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG;YAChB,SAAS;YACT,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,KAAK;YAChB,WAAW;SACS,CAAC;IACzB,CAAC;IAED,OAAO;QACL,cAAc;QACd,eAAe;QACf,WAAW;QACX,cAAc;KACf,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import type { Response } from 'express';
|
|
|
2
2
|
import type { AuthService } from '@boopkit/cap-users';
|
|
3
3
|
import { AuthValidationError } from '@boopkit/cap-users';
|
|
4
4
|
|
|
5
|
-
/** Extended Express Request with auth fields set by
|
|
5
|
+
/** Extended Express Request with auth fields set by resolveVisitor middleware. */
|
|
6
6
|
interface AuthRequest {
|
|
7
7
|
body: Record<string, any>;
|
|
8
8
|
query: Record<string, any>;
|
|
@@ -6,7 +6,7 @@ import createAuthRouter from '../routes/auth';
|
|
|
6
6
|
|
|
7
7
|
const { authService, identityService, userService } = UserService;
|
|
8
8
|
|
|
9
|
-
const {
|
|
9
|
+
const { resolveVisitor, getOrCreateUser, addAuthContext, requireAuth } = createAuthMiddleware(
|
|
10
10
|
{ authService, identityService, userService },
|
|
11
11
|
{
|
|
12
12
|
cookieName: 'auth_id',
|
|
@@ -17,4 +17,4 @@ const { ensureVisitor, addAuthContext, requireAuth } = createAuthMiddleware(
|
|
|
17
17
|
/** Pre-built auth routes (signup, login, logout). Ready to mount with app.use(). */
|
|
18
18
|
const authRoutes = createAuthRouter({ authService });
|
|
19
19
|
|
|
20
|
-
export {
|
|
20
|
+
export { resolveVisitor, getOrCreateUser, addAuthContext, requireAuth, authRoutes };
|