bro-framework 2.3.0 → 2.3.1
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/README.md +1 -1
- package/package.json +1 -1
- package/src/server.js +11 -14
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
23
|
-
>
|
|
23
|
+
> Skip the boilerplate. bro.js gives you file-based routing, automatic Zod validation, JWT auth, and WebSockets right out of the box. Just write your business logic, return an object, and let the framework handle the rest.
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
package/package.json
CHANGED
package/src/server.js
CHANGED
|
@@ -106,21 +106,18 @@ export async function createServer(globalConfig, routesDir, db) {
|
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return res.status(401).json({ error: 'Unauthorized', details: authResult.error });
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
ctx.user = authResult.payload;
|
|
109
|
+
const authHeader = req.headers.authorization;
|
|
110
|
+
if ((!authHeader || !authHeader.startsWith('Bearer ')) && routeConfig.auth) {
|
|
111
|
+
return res.status(401).json({ error: 'Unauthorized', details: 'Missing or invalid Bearer token' });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const token = authHeader?.split(' ')[1] ?? '';
|
|
115
|
+
const authResult = verifyJwt(token, globalConfig.jwtSecret);
|
|
116
|
+
|
|
117
|
+
if (!authResult.valid && routeConfig.auth) {
|
|
118
|
+
return res.status(401).json({ error: 'Unauthorized', details: authResult.error });
|
|
123
119
|
}
|
|
120
|
+
ctx.user = authResult?.payload ?? null;
|
|
124
121
|
|
|
125
122
|
if (paramsSchema) {
|
|
126
123
|
const result = paramsSchema.safeParse(req.params);
|