@tylix/core 1.4.0 → 1.5.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/package.json +4 -4
- package/src/http/requireAuth.js +15 -4
- package/src/http/statusPage.js +20 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tylix/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "The Tylix server core: HTTP server and router, logging, metrics and health checks, a shared store (memory, database, Redis), cache, rate limiting, queue, scheduler and channels.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Mbiyrukzz",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"test": "node --test 'src/**/*.test.js'"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@tylix/auth": "^1.
|
|
48
|
-
"@tylix/orm": "^1.
|
|
49
|
-
"@tylix/shared": "^1.
|
|
47
|
+
"@tylix/auth": "^1.5.0",
|
|
48
|
+
"@tylix/orm": "^1.5.0",
|
|
49
|
+
"@tylix/shared": "^1.5.0",
|
|
50
50
|
"ws": "^8.18.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
package/src/http/requireAuth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { verifyTylixAccessToken, ACCESS_TOKEN_COOKIE } from "@tylix/auth";
|
|
2
2
|
|
|
3
3
|
// Shared across packages (Symbol.for), so `tylix dev` can print a lock next
|
|
4
4
|
// to every guarded route without importing anything from here.
|
|
@@ -10,9 +10,14 @@ const AUTH_MARK = Symbol.for("tylix.requireAuth");
|
|
|
10
10
|
* browser app now uses), then falls back to an
|
|
11
11
|
* "Authorization: Bearer <token>" header (for non-browser API clients
|
|
12
12
|
* that can't rely on cookies). On success, req.user is set to the
|
|
13
|
-
* token's payload (e.g. { userId }); on failure, responds 401 and
|
|
13
|
+
* token's payload (e.g. { userId, sid }); on failure, responds 401 and
|
|
14
14
|
* never calls the wrapped handler.
|
|
15
15
|
*
|
|
16
|
+
* Only real access tokens pass: email-verification links and other
|
|
17
|
+
* purpose tokens are refused, and when the app's AuthController manages
|
|
18
|
+
* sessions, a token whose session was ended (logout, "sign out
|
|
19
|
+
* everywhere", password reset) is refused immediately.
|
|
20
|
+
*
|
|
16
21
|
* options.hydrate(payload, req) is optional. It runs after the token is
|
|
17
22
|
* verified and can add fields to req.user (for example a team id):
|
|
18
23
|
* - return an object -> its fields are merged into req.user
|
|
@@ -27,7 +32,7 @@ export function requireAuth(handler, secret, options = {}) {
|
|
|
27
32
|
|
|
28
33
|
const authHeader = req.headers?.authorization || "";
|
|
29
34
|
const [scheme, headerToken] = authHeader.split(" ");
|
|
30
|
-
const bearerToken = scheme
|
|
35
|
+
const bearerToken = /^bearer$/i.test(scheme ?? "") ? headerToken : null;
|
|
31
36
|
|
|
32
37
|
const token = cookieToken || bearerToken;
|
|
33
38
|
|
|
@@ -35,7 +40,13 @@ export function requireAuth(handler, secret, options = {}) {
|
|
|
35
40
|
return res.status(401).json({ error: "Not authenticated." });
|
|
36
41
|
}
|
|
37
42
|
|
|
38
|
-
|
|
43
|
+
let result;
|
|
44
|
+
try {
|
|
45
|
+
result = await verifyTylixAccessToken(token, secret);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error("[auth] token check failed:", error);
|
|
48
|
+
return res.status(500).json({ error: "Couldn't check your session." });
|
|
49
|
+
}
|
|
39
50
|
if (!result.valid) {
|
|
40
51
|
return res.status(401).json({ error: result.error || "Invalid token." });
|
|
41
52
|
}
|
package/src/http/statusPage.js
CHANGED
|
@@ -56,18 +56,18 @@ export function renderStatusPage({
|
|
|
56
56
|
<style>
|
|
57
57
|
* { box-sizing: border-box; }
|
|
58
58
|
:root {
|
|
59
|
-
--bg:#
|
|
60
|
-
--text:#
|
|
61
|
-
--success:#
|
|
62
|
-
--error:#
|
|
63
|
-
--notfound:#
|
|
59
|
+
--bg:#f3f2f6; --card:#ffffff; --border:#dedbe6; --border-strong:#c9c5d4;
|
|
60
|
+
--text:#17151c; --muted:#6b6878; --brand:#0034ca; --brand-hover:#1a4be0;
|
|
61
|
+
--success:#0d8c67; --success-soft:rgba(13,140,103,.12);
|
|
62
|
+
--error:#cd3c3c; --error-soft:rgba(205,60,60,.10);
|
|
63
|
+
--notfound:#bd6226; --notfound-soft:rgba(189,98,38,.12);
|
|
64
64
|
}
|
|
65
65
|
html.dark {
|
|
66
|
-
--bg:#
|
|
67
|
-
--text:#
|
|
68
|
-
--success:#
|
|
69
|
-
--error:#
|
|
70
|
-
--notfound:#
|
|
66
|
+
--bg:#17161c; --card:#211f27; --border:#34313d; --border-strong:#46424f;
|
|
67
|
+
--text:#ecebf1; --muted:#9592a3; --brand:#3563ff; --brand-hover:#547cff;
|
|
68
|
+
--success:#5fe3b5; --success-soft:rgba(95,227,181,.12);
|
|
69
|
+
--error:#ff7b7b; --error-soft:rgba(255,123,123,.12);
|
|
70
|
+
--notfound:#ffb38a; --notfound-soft:rgba(255,179,138,.12);
|
|
71
71
|
}
|
|
72
72
|
html { color-scheme: light; } html.dark { color-scheme: dark; }
|
|
73
73
|
body {
|
|
@@ -77,12 +77,13 @@ export function renderStatusPage({
|
|
|
77
77
|
}
|
|
78
78
|
.card {
|
|
79
79
|
width:100%; max-width:440px; text-align:center; padding:36px 32px 32px;
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
border:1px solid transparent; border-radius:20px;
|
|
81
|
+
background:linear-gradient(var(--card),var(--card)) padding-box, linear-gradient(135deg,#6fe0ea,#c8f07a) border-box;
|
|
82
|
+
box-shadow:0 0 32px -8px rgba(111,224,234,.35), 0 12px 32px -16px rgba(0,0,0,.25);
|
|
82
83
|
}
|
|
83
|
-
html.dark .card { box-shadow:none; }
|
|
84
84
|
.brand { display:inline-flex; align-items:center; gap:8px; margin-bottom:24px; font-weight:600; color:var(--text); text-decoration:none; }
|
|
85
|
-
.brand img {
|
|
85
|
+
.brand img { height:20px; width:auto; }
|
|
86
|
+
html.dark .brand img { filter:brightness(1.7) saturate(1.1); }
|
|
86
87
|
.icon { width:60px; height:60px; margin:0 auto 18px; border-radius:50%; display:grid; place-items:center;
|
|
87
88
|
color:var(--tone); background:var(--tone-soft); }
|
|
88
89
|
.tone-success { --tone:var(--success); --tone-soft:var(--success-soft); }
|
|
@@ -93,12 +94,12 @@ export function renderStatusPage({
|
|
|
93
94
|
p.msg { margin:0 0 24px; color:var(--muted); font-size:14px; line-height:1.6; }
|
|
94
95
|
.actions { display:flex; gap:10px; justify-content:center; flex-wrap:wrap; }
|
|
95
96
|
.btn {
|
|
96
|
-
font-size:14px; font-weight:600; text-decoration:none; padding:9px 18px; border-radius:
|
|
97
|
+
font-size:14px; font-weight:600; text-decoration:none; padding:9px 18px; border-radius:9px;
|
|
97
98
|
color:var(--text); border:1px solid var(--border-strong); background:transparent; transition:all .15s;
|
|
98
99
|
}
|
|
99
|
-
.btn:hover { border-color:var(--
|
|
100
|
-
.btn-primary { color:#fff; border-color:transparent; background:
|
|
101
|
-
.btn-primary:hover { color:#fff;
|
|
100
|
+
.btn:hover { border-color:var(--brand); color:var(--brand); }
|
|
101
|
+
.btn-primary { color:#fff; border-color:transparent; background:var(--brand); }
|
|
102
|
+
.btn-primary:hover { color:#fff; background:var(--brand-hover); box-shadow:0 6px 18px -8px var(--brand); }
|
|
102
103
|
.ref { margin:22px 0 0; font-size:12px; color:var(--muted); }
|
|
103
104
|
.ref code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size:11px; padding:2px 6px;
|
|
104
105
|
border-radius:6px; background:var(--bg); border:1px solid var(--border); user-select:all; }
|
|
@@ -106,7 +107,7 @@ export function renderStatusPage({
|
|
|
106
107
|
</head>
|
|
107
108
|
<body>
|
|
108
109
|
<div class="card tone-${esc(tone)}">
|
|
109
|
-
<a class="brand" href="/"><img src="/logo-mark.
|
|
110
|
+
<a class="brand" href="/"><img src="/logo-mark.svg" alt="" onerror="if(!this.dataset.png){this.dataset.png=1;this.src='/logo-mark.png'}else{this.remove()}">Tylix</a>
|
|
110
111
|
<div class="icon">${ICONS[tone] ?? ICONS.error}</div>
|
|
111
112
|
${code ? `<p class="code">${esc(code)}</p>` : ''}
|
|
112
113
|
<h1>${esc(title)}</h1>
|