feat: wip cli token authentication

This commit is contained in:
Mauricio Siu
2024-06-05 22:42:11 -06:00
parent 113df9ae12
commit b9bff95c3d
16 changed files with 2845 additions and 56 deletions

View File

@@ -1,4 +1,8 @@
import { createTRPCRouter, protectedProcedure } from "@/server/api/trpc";
import {
cliProcedure,
createTRPCRouter,
protectedProcedure,
} from "@/server/api/trpc";
import { db } from "@/server/db";
import {
apiCreateProject,
@@ -44,6 +48,30 @@ export const projectRouter = createTRPCRouter({
await addNewProject(ctx.user.authId, project.projectId);
}
return project;
} catch (error) {
console.log(error);
throw new TRPCError({
code: "BAD_REQUEST",
message: "Error to create the project",
cause: error,
});
}
}),
createCLI: protectedProcedure
.input(apiCreateProject)
.mutation(async ({ ctx, input }) => {
try {
console.log(ctx);
if (ctx.user.rol === "user") {
await checkProjectAccess(ctx.user.authId, "create");
}
const project = await createProject(input);
if (ctx.user.rol === "user") {
await addNewProject(ctx.user.authId, project.projectId);
}
return project;
} catch (error) {
console.log(error);