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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/src/server.js +11 -14
package/README.md CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  ---
22
22
 
23
- > "NestJS wants four decorators, three modules, and an existential crisis just to handle a GET request. Express makes you write the same 40 lines of CORS, JSON parsing, and auth middleware for every project. bro.js gives you file routing, auto-validation, JWT auth, WebSockets, and live docs out of the box. Be honest: you just want to return an object."
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bro-framework",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "The No-BS Backend Framework for Node.js",
5
5
  "repository": {
6
6
  "type": "git",
package/src/server.js CHANGED
@@ -106,21 +106,18 @@ export async function createServer(globalConfig, routesDir, db) {
106
106
  }
107
107
  };
108
108
 
109
- if (routeConfig.auth) {
110
- const authHeader = req.headers.authorization;
111
- if (!authHeader || !authHeader.startsWith('Bearer ')) {
112
- return res.status(401).json({ error: 'Unauthorized', details: 'Missing or invalid Bearer token' });
113
- }
114
-
115
- const token = authHeader.split(' ')[1];
116
- const authResult = verifyJwt(token, globalConfig.jwtSecret);
117
-
118
- if (!authResult.valid) {
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);