@everystack/api 0.2.1 → 0.2.2
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 +1 -1
- package/src/handler/index.ts +12 -6
package/package.json
CHANGED
package/src/handler/index.ts
CHANGED
|
@@ -547,6 +547,12 @@ export function createHandler(db: DrizzleDb, schema: Schema, options?: HandlerOp
|
|
|
547
547
|
const result = await verifyUserToken(request, options.auth);
|
|
548
548
|
if (result.error) return result.error;
|
|
549
549
|
user = result.user;
|
|
550
|
+
} else if (request.headers.get('authorization')) {
|
|
551
|
+
// Public route with token present — verify opportunistically.
|
|
552
|
+
// If valid, the request runs as authenticated (better RLS access).
|
|
553
|
+
// If invalid, ignore and fall through as anonymous.
|
|
554
|
+
const result = await verifyUserToken(request, options.auth);
|
|
555
|
+
if (!result.error) user = result.user;
|
|
550
556
|
}
|
|
551
557
|
|
|
552
558
|
if (user && options.auth.onAuthenticated) {
|
|
@@ -812,7 +818,7 @@ async function handleGet(
|
|
|
812
818
|
};
|
|
813
819
|
if (cacheControl) aggHeaders['Cache-Control'] = cacheControl;
|
|
814
820
|
|
|
815
|
-
return new Response(JSON.stringify(transformResponse(
|
|
821
|
+
return new Response(JSON.stringify(stripHiddenColumns(transformResponse(serialized, options), tableName, options)), {
|
|
816
822
|
status: 200,
|
|
817
823
|
headers: aggHeaders,
|
|
818
824
|
});
|
|
@@ -926,7 +932,7 @@ async function handleGet(
|
|
|
926
932
|
};
|
|
927
933
|
if (cacheControl) getHeaders['Cache-Control'] = cacheControl;
|
|
928
934
|
|
|
929
|
-
return new Response(JSON.stringify(transformResponse(
|
|
935
|
+
return new Response(JSON.stringify(stripHiddenColumns(transformResponse(responseData, options), tableName, options)), {
|
|
930
936
|
status: 200,
|
|
931
937
|
headers: getHeaders,
|
|
932
938
|
});
|
|
@@ -1228,7 +1234,7 @@ async function handlePost(
|
|
|
1228
1234
|
try { await hook.afterCreate(rows[0], user, client); } catch {}
|
|
1229
1235
|
}
|
|
1230
1236
|
|
|
1231
|
-
return json(transformResponse(
|
|
1237
|
+
return json(stripHiddenColumns(transformResponse(rows[0], options), tableName, options), 201);
|
|
1232
1238
|
}
|
|
1233
1239
|
|
|
1234
1240
|
async function handlePatch(
|
|
@@ -1305,7 +1311,7 @@ async function handlePatch(
|
|
|
1305
1311
|
try { await hook.afterUpdate(rows, user, client); } catch {}
|
|
1306
1312
|
}
|
|
1307
1313
|
|
|
1308
|
-
return json(transformResponse(
|
|
1314
|
+
return json(stripHiddenColumns(transformResponse(rows, options), tableName, options), 200);
|
|
1309
1315
|
}
|
|
1310
1316
|
|
|
1311
1317
|
async function handleDelete(
|
|
@@ -1375,7 +1381,7 @@ async function handleDelete(
|
|
|
1375
1381
|
try { await hook.afterDelete(rows, user, client); } catch {}
|
|
1376
1382
|
}
|
|
1377
1383
|
|
|
1378
|
-
return json(transformResponse(
|
|
1384
|
+
return json(stripHiddenColumns(transformResponse(rows, options), tableName, options), 200);
|
|
1379
1385
|
}
|
|
1380
1386
|
}
|
|
1381
1387
|
|
|
@@ -1394,7 +1400,7 @@ async function handleDelete(
|
|
|
1394
1400
|
try { await hook.afterDelete(rows, user, client); } catch {}
|
|
1395
1401
|
}
|
|
1396
1402
|
|
|
1397
|
-
return json(transformResponse(
|
|
1403
|
+
return json(stripHiddenColumns(transformResponse(rows, options), tableName, options), 200);
|
|
1398
1404
|
}
|
|
1399
1405
|
|
|
1400
1406
|
interface JsonPath {
|