jackmcbride_98
jackmcbride_98
TTCTheo's Typesafe Cult
Created by Sturlen on 2/5/2024 in #questions
How do you safely store your API keys?
If you have the sign ins to where you got the keys from, then you can always go and get them from those websites.
7 replies
TTCTheo's Typesafe Cult
Created by sommeeer on 11/30/2023 in #questions
Revalidating a SSG path in a tRPC procedure
Is this what you are looking for?
8 replies
TTCTheo's Typesafe Cult
Created by sommeeer on 11/30/2023 in #questions
Revalidating a SSG path in a tRPC procedure
8 replies
TTCTheo's Typesafe Cult
Created by ar on 11/9/2023 in #questions
Standards for useNavigate and useRouter for creating npm package
They can be in the same library, just different exports
4 replies
TTCTheo's Typesafe Cult
Created by ar on 11/9/2023 in #questions
Standards for useNavigate and useRouter for creating npm package
You will probably have to make different versions for react-router and next-router
4 replies
TTCTheo's Typesafe Cult
Created by jackmcbride_98 on 10/4/2023 in #questions
How do I revalidatePath from a trpc router?
import { z } from "zod";
import {
createTRPCRouter,
publicProcedure,
protectedProcedure,
} from "@/server/api/trpc";
import { formSchema } from "@/pages/admin";

export const gigsRouter = createTRPCRouter({
getAll: publicProcedure.query(({ ctx }) => {
return ctx.prisma.gigs.findMany();
}),

create: protectedProcedure
.input(formSchema)
.mutation(async ({ ctx, input }) => {
const returnThis = await ctx.prisma.gigs.create({
data: {
...input,
date: new Date(input.date),
},
});

await ctx.res.revalidate("/");
return returnThis;
}),

delete: protectedProcedure
.input(z.object({ id: z.string() }))
.mutation(async ({ ctx, input }) => {
const returnThis = await ctx.prisma.gigs.delete({
where: { id: input.id },
});

await ctx.res.revalidate("/");
return returnThis;
}),
});
import { z } from "zod";
import {
createTRPCRouter,
publicProcedure,
protectedProcedure,
} from "@/server/api/trpc";
import { formSchema } from "@/pages/admin";

export const gigsRouter = createTRPCRouter({
getAll: publicProcedure.query(({ ctx }) => {
return ctx.prisma.gigs.findMany();
}),

create: protectedProcedure
.input(formSchema)
.mutation(async ({ ctx, input }) => {
const returnThis = await ctx.prisma.gigs.create({
data: {
...input,
date: new Date(input.date),
},
});

await ctx.res.revalidate("/");
return returnThis;
}),

delete: protectedProcedure
.input(z.object({ id: z.string() }))
.mutation(async ({ ctx, input }) => {
const returnThis = await ctx.prisma.gigs.delete({
where: { id: input.id },
});

await ctx.res.revalidate("/");
return returnThis;
}),
});
11 replies
TTCTheo's Typesafe Cult
Created by jackmcbride_98 on 10/4/2023 in #questions
How do I revalidatePath from a trpc router?
Adn then you can do this in gigsRouter file
11 replies
TTCTheo's Typesafe Cult
Created by jackmcbride_98 on 10/4/2023 in #questions
How do I revalidatePath from a trpc router?
Add this to your trpc.ts file
11 replies
TTCTheo's Typesafe Cult
Created by jackmcbride_98 on 10/4/2023 in #questions
How do I revalidatePath from a trpc router?
/**
* This helper generates the "internals" for a tRPC context. If you need to use it, you can export
* it from here.
*
* Examples of things you may need it for:
* - testing, so we don't have to mock Next.js' req/res
* - tRPC's `createSSGHelpers`, where we don't have req/res
*
* @see https://create.t3.gg/en/usage/trpc#-serverapitrpcts
*/
const createInnerTRPCContext = (opts: CreateContextOptions) => {
return {
session: opts.session,
prisma,
res: opts.res,
};
};

/**
* This is the actual context you will use in your router. It will be used to process every request
* that goes through your tRPC endpoint.
*
* @see https://trpc.io/docs/context
*/
export const createTRPCContext = async (opts: CreateNextContextOptions) => {
const { req, res } = opts;

// Get the session from the server using the getServerSession wrapper function
const session = await getServerAuthSession({ req, res });

return createInnerTRPCContext({
session,
res,
});
};
/**
* This helper generates the "internals" for a tRPC context. If you need to use it, you can export
* it from here.
*
* Examples of things you may need it for:
* - testing, so we don't have to mock Next.js' req/res
* - tRPC's `createSSGHelpers`, where we don't have req/res
*
* @see https://create.t3.gg/en/usage/trpc#-serverapitrpcts
*/
const createInnerTRPCContext = (opts: CreateContextOptions) => {
return {
session: opts.session,
prisma,
res: opts.res,
};
};

/**
* This is the actual context you will use in your router. It will be used to process every request
* that goes through your tRPC endpoint.
*
* @see https://trpc.io/docs/context
*/
export const createTRPCContext = async (opts: CreateNextContextOptions) => {
const { req, res } = opts;

// Get the session from the server using the getServerSession wrapper function
const session = await getServerAuthSession({ req, res });

return createInnerTRPCContext({
session,
res,
});
};
11 replies
TTCTheo's Typesafe Cult
Created by jackmcbride_98 on 10/4/2023 in #questions
How do I revalidatePath from a trpc router?
Ok solved it
11 replies
TTCTheo's Typesafe Cult
Created by jackmcbride_98 on 10/4/2023 in #questions
How do I revalidatePath from a trpc router?
Something like this
11 replies
TTCTheo's Typesafe Cult
Created by jackmcbride_98 on 10/4/2023 in #questions
How do I revalidatePath from a trpc router?
11 replies
TTCTheo's Typesafe Cult
Created by jackmcbride_98 on 10/4/2023 in #questions
What to do about Date not serializable when calling getServerSideProps?
Here's my next.config.mjs
6 replies
TTCTheo's Typesafe Cult
Created by jackmcbride_98 on 10/4/2023 in #questions
What to do about Date not serializable when calling getServerSideProps?
/** * Run build or dev with SKIP_ENV_VALIDATION to skip env validation. This is especially useful * for Docker builds. */ await import("./src/env.mjs"); import { withSuperjson } from "next-superjson"; /** @type {import("next").NextConfig} */ const config = { reactStrictMode: true, /** * If you are using appDir then you must comment the below i18n config out. * * @see https://github.com/vercel/next.js/issues/41980 */ i18n: { locales: ["en"], defaultLocale: "en", }, }; export default withSuperjson()(config);
6 replies
TTCTheo's Typesafe Cult
Created by jackmcbride_98 on 10/4/2023 in #questions
What to do about Date not serializable when calling getServerSideProps?
Found the solution, use withsuperjson
6 replies
TTCTheo's Typesafe Cult
Created by oljimenez on 8/17/2023 in #questions
Array<string> vs Record<key, true>?
Fair, you could have a go at creating that feature in the Prisma codebase, or just accept that you'll have different syntax for some queries. I've heard good things about kysely, could also just switch over to that if its better
14 replies
TTCTheo's Typesafe Cult
Created by oljimenez on 8/17/2023 in #questions
Array<string> vs Record<key, true>?
Would you be able to do it in seperate queries? I know thats a pain, but might be a bit easier than using kysely and rebuilding it in a prisma way XD
14 replies
TTCTheo's Typesafe Cult
Created by oljimenez on 8/17/2023 in #questions
Array<string> vs Record<key, true>?
I get why you don't like it, what are the use cases that prisma doesnt support? Perhaps you can find another way round it or make a PR to the library to support it
14 replies
TTCTheo's Typesafe Cult
Created by oljimenez on 8/17/2023 in #questions
Array<string> vs Record<key, true>?
Seems a little obsessive to me. Could you make a wrapper around kysely that basically does things in the way prisma does and then maps it to kysely?
14 replies