lyricaldevil
lyricaldevil
TTCTheo's Typesafe Cult
Created by lyricaldevil on 10/3/2024 in #questions
ESLint error in NextConfig when customizing webpack
No description
5 replies
TTCTheo's Typesafe Cult
Created by lyricaldevil on 2/5/2024 in #questions
Encryption/Security questions
I'm working on an application in a highly regulated industry and want to use UT, but I have questions about how S3 is configured behind the scenes and what kind of encryption/security settings are being set. Is this documented anywhere? I could probably read through the code and figure it out, but I was hoping to avoid that 😅
2 replies
TTCTheo's Typesafe Cult
Created by lyricaldevil on 5/17/2023 in #questions
More Clerk + tRPC weirdness
I've seen a few questions recently related to the interaction between Clerk and tRPC, but my issue is apparently just different enough that it's not solved by the same things. I'm attempting to make the root route ("/") public and everything else protected, but any tRPC calls return a 401 error. For reference:
// src/middleware.ts
export default authMiddleware({
publicRoutes: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
});

export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};
// src/middleware.ts
export default authMiddleware({
publicRoutes: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
});

export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};
// src/server/api/trpc.ts
const createInnerTRPCContext = ({ auth }: AuthContext) => {
return {
auth,
prisma,
};
};

export const createTRPCContext = async ({
req,
res,
}: CreateNextContextOptions) => {
return createInnerTRPCContext({
auth: getAuth(req),
});
};

import { initTRPC, TRPCError } from "@trpc/server";
import superjson from "superjson";
import { ZodError } from "zod";

const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
return {
...shape,
data: {
...shape.data,
zodError:
error.cause instanceof ZodError ? error.cause.flatten() : null,
},
};
},
});

export const createTRPCRouter = t.router;

export const publicProcedure = t.procedure;

const enforceUserIsAuthed = t.middleware(({ ctx, next }) => {
if (!ctx.auth.userId) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}

return next({
ctx: {
// infers the `session` as non-nullable
auth: ctx.auth,
},
});
});

export const protectedProcedure = t.procedure.use(enforceUserIsAuthed);
// src/server/api/trpc.ts
const createInnerTRPCContext = ({ auth }: AuthContext) => {
return {
auth,
prisma,
};
};

export const createTRPCContext = async ({
req,
res,
}: CreateNextContextOptions) => {
return createInnerTRPCContext({
auth: getAuth(req),
});
};

import { initTRPC, TRPCError } from "@trpc/server";
import superjson from "superjson";
import { ZodError } from "zod";

const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
return {
...shape,
data: {
...shape.data,
zodError:
error.cause instanceof ZodError ? error.cause.flatten() : null,
},
};
},
});

export const createTRPCRouter = t.router;

export const publicProcedure = t.procedure;

const enforceUserIsAuthed = t.middleware(({ ctx, next }) => {
if (!ctx.auth.userId) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}

return next({
ctx: {
// infers the `session` as non-nullable
auth: ctx.auth,
},
});
});

export const protectedProcedure = t.procedure.use(enforceUserIsAuthed);
11 replies