Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/webapp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ build-storybook.log
storybook-static

/prisma/seed.js
/prisma/populate.js
/prisma/populate.js
.memory-snapshots
17 changes: 14 additions & 3 deletions apps/webapp/app/routes/admin.api.v1.gc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { type DataFunctionArgs } from "@remix-run/node";
import { PerformanceObserver } from "node:perf_hooks";
import { runInNewContext } from "node:vm";
import v8 from "v8";
import { requireUser } from "~/services/session.server";
import { prisma } from "~/db.server";
import { authenticateApiRequestWithPersonalAccessToken } from "~/services/personalAccessToken.server";

async function waitTillGcFinishes() {
let resolver: (value: PerformanceEntry) => void;
Expand Down Expand Up @@ -35,9 +36,19 @@ async function waitTillGcFinishes() {
}

export async function loader({ request }: DataFunctionArgs) {
const user = await requireUser(request);
const authenticationResult = await authenticateApiRequestWithPersonalAccessToken(request);

if (!user.admin) {
if (!authenticationResult) {
throw new Response("You must be an admin to perform this action", { status: 403 });
}

const user = await prisma.user.findFirst({
where: {
id: authenticationResult.userId,
},
});

if (!user?.admin) {
throw new Response("You must be an admin to perform this action", { status: 403 });
}

Expand Down
17 changes: 14 additions & 3 deletions apps/webapp/app/routes/admin.api.v1.snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import os from "os";
import path from "path";
import { PassThrough } from "stream";
import v8 from "v8";
import { requireUser } from "~/services/session.server";
import { prisma } from "~/db.server";
import { authenticateApiRequestWithPersonalAccessToken } from "~/services/personalAccessToken.server";

// Format date as yyyy-MM-dd HH_mm_ss_SSS
function formatDate(date: Date) {
Expand All @@ -24,9 +25,19 @@ function formatDate(date: Date) {
}

export async function loader({ request }: DataFunctionArgs) {
const user = await requireUser(request);
const authenticationResult = await authenticateApiRequestWithPersonalAccessToken(request);

if (!user.admin) {
if (!authenticationResult) {
throw new Response("You must be an admin to perform this action", { status: 403 });
}

const user = await prisma.user.findFirst({
where: {
id: authenticationResult.userId,
},
});

if (!user?.admin) {
throw new Response("You must be an admin to perform this action", { status: 403 });
}

Expand Down
20 changes: 20 additions & 0 deletions apps/webapp/app/routes/api.v1.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ActionFunctionArgs } from "@remix-run/server-runtime";

export async function action({ request }: ActionFunctionArgs) {
if (process.env.NODE_ENV === "production") {
return new Response("Not found", { status: 404 });
}

return new Response(
JSON.stringify({
data: {
id: "123",
type: "mock",
attributes: {
name: "Mock",
},
},
}),
{ status: 200 }
);
}
Loading
Loading