Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
♻️ Use TWT for IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Aug 11, 2020
1 parent f406232 commit 2c20106
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/_staart/helpers/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ export const prisma = new PrismaClient({
prisma.$use(async (params, next) => {
const result = await next(params);
console.log("Got result", result);
console.log("Secret it", config("twtSecret"));
if (typeof result === "object" && !Array.isArray(result))
if (result.id) result.id = sign(result.id, config("twtSecret"));
if (typeof result.id === "number")
result.id = sign(String(result.id), config("twtSecret"));
if (Array.isArray(result))
result.map((result) => {
if (typeof result.id === "number")
result.id = sign(String(result.id), config("twtSecret"));
return result;
});
return result;
});

Expand Down
6 changes: 3 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { cosmicSync, config } from "@anandchowdhary/cosmic";
cosmicSync("staart");

import { success } from "@staart/errors";
import { Controller, Get, Server } from "@staart/server";
import { setupMiddleware } from "@staart/server";
import { cosmicSync, config } from "@anandchowdhary/cosmic";

import {
errorHandler,
Expand All @@ -10,8 +12,6 @@ import {
trackingHandler,
} from "./_staart/helpers/middleware";

cosmicSync("staart");

@Controller(config("controllerPrefix"))
class RootController {
@Get()
Expand Down

0 comments on commit 2c20106

Please sign in to comment.