carnegiepilled
carnegiepilled
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Cxstum on 11/22/2023 in #questions
Get username from a Clerk user
where you do auth()
23 replies
TTCTheo's Typesafe Cult
Created by Cxstum on 11/22/2023 in #questions
Get username from a Clerk user
show the parent component
23 replies
TTCTheo's Typesafe Cult
Created by Cxstum on 11/22/2023 in #questions
Get username from a Clerk user
and where is the user coming from?
23 replies
TTCTheo's Typesafe Cult
Created by Cxstum on 11/22/2023 in #questions
Get username from a Clerk user
if you don't know that you need it, don't add it – you will waste days and it's not useful for the users
23 replies
TTCTheo's Typesafe Cult
Created by Cxstum on 11/22/2023 in #questions
Get username from a Clerk user
no trpc is complex
23 replies
TTCTheo's Typesafe Cult
Created by Cxstum on 11/22/2023 in #questions
Get username from a Clerk user
can you show code?
23 replies
TTCTheo's Typesafe Cult
Created by Pavstermeister on 11/5/2023 in #questions
Configuring Clerk on the latest release of t3 with tRPC
what's the error?
123 replies
TTCTheo's Typesafe Cult
Created by Cxstum on 11/22/2023 in #questions
Get username from a Clerk user
@Cxstum user.firstName on the User object
23 replies
TTCTheo's Typesafe Cult
Created by Pavstermeister on 11/5/2023 in #questions
Configuring Clerk on the latest release of t3 with tRPC
yes
123 replies
TTCTheo's Typesafe Cult
Created by Pavstermeister on 11/5/2023 in #questions
Configuring Clerk on the latest release of t3 with tRPC
@Spark
123 replies
TTCTheo's Typesafe Cult
Created by Pavstermeister on 11/5/2023 in #questions
Configuring Clerk on the latest release of t3 with tRPC
import { initTRPC, TRPCError } from "@trpc/server";
import { type NextRequest } from "next/server";
import superjson from "superjson";
import { ZodError } from "zod";

import { db } from "~/server/db";

import { clerkClient, decodeJwt, getAuth, type User, type SignedInAuthObject, SignedOutAuthObject } from '@clerk/nextjs/server';
import { auth } from "@clerk/nextjs";


interface CreateContextOptions {
headers: Headers;
db: typeof db;
// auth: User;
auth: SignedInAuthObject | SignedOutAuthObject;
}

export const createTRPCContext = async (opts: { headers: Headers }) => {
const session = auth();
// const session = getAuth(opts)

return {
db,
auth: session,
...opts,
};
};


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,
},
};
},
});

/**
* 3. ROUTER & PROCEDURE (THE IMPORTANT BIT)
*
* These are the pieces you use to build your tRPC API. You should import these a lot in the
* "/src/server/api/routers" directory.
*/

/**
* This is how you create new routers and sub-routers in your tRPC API.
*
* @see https://trpc.io/docs/router
*/
export const createTRPCRouter = t.router;

const isAuthed = t.middleware(({ next, ctx }) => {
if (!ctx.auth.userId) {
throw new TRPCError({ code: "UNAUTHORIZED", message: "Not authenticated" });
}
return next({
ctx: {
auth: ctx.auth,
db,
},
});
});


export const publicProcedure = t.procedure;
export const protectedProcedure = t.procedure.use(isAuthed);
import { initTRPC, TRPCError } from "@trpc/server";
import { type NextRequest } from "next/server";
import superjson from "superjson";
import { ZodError } from "zod";

import { db } from "~/server/db";

import { clerkClient, decodeJwt, getAuth, type User, type SignedInAuthObject, SignedOutAuthObject } from '@clerk/nextjs/server';
import { auth } from "@clerk/nextjs";


interface CreateContextOptions {
headers: Headers;
db: typeof db;
// auth: User;
auth: SignedInAuthObject | SignedOutAuthObject;
}

export const createTRPCContext = async (opts: { headers: Headers }) => {
const session = auth();
// const session = getAuth(opts)

return {
db,
auth: session,
...opts,
};
};


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,
},
};
},
});

/**
* 3. ROUTER & PROCEDURE (THE IMPORTANT BIT)
*
* These are the pieces you use to build your tRPC API. You should import these a lot in the
* "/src/server/api/routers" directory.
*/

/**
* This is how you create new routers and sub-routers in your tRPC API.
*
* @see https://trpc.io/docs/router
*/
export const createTRPCRouter = t.router;

const isAuthed = t.middleware(({ next, ctx }) => {
if (!ctx.auth.userId) {
throw new TRPCError({ code: "UNAUTHORIZED", message: "Not authenticated" });
}
return next({
ctx: {
auth: ctx.auth,
db,
},
});
});


export const publicProcedure = t.procedure;
export const protectedProcedure = t.procedure.use(isAuthed);
123 replies
TTCTheo's Typesafe Cult
Created by Pavstermeister on 11/5/2023 in #questions
Configuring Clerk on the latest release of t3 with tRPC
search the help threads for the cookies solution - its really easy
123 replies
TTCTheo's Typesafe Cult
Created by Pavstermeister on 11/5/2023 in #questions
Configuring Clerk on the latest release of t3 with tRPC
if you don't want to use RSC for some reason, then the solution is even easier
123 replies
TTCTheo's Typesafe Cult
Created by Pavstermeister on 11/5/2023 in #questions
Configuring Clerk on the latest release of t3 with tRPC
depends tho– this is only required if you're using RSC ^^
123 replies
TTCTheo's Typesafe Cult
Created by Pavstermeister on 11/5/2023 in #questions
Configuring Clerk on the latest release of t3 with tRPC
123 replies
TTCTheo's Typesafe Cult
Created by Pavstermeister on 11/5/2023 in #questions
Configuring Clerk on the latest release of t3 with tRPC
i do
123 replies
TTCTheo's Typesafe Cult
Created by Pavstermeister on 11/5/2023 in #questions
Configuring Clerk on the latest release of t3 with tRPC
thank you for understanding!
123 replies
TTCTheo's Typesafe Cult
Created by Pavstermeister on 11/5/2023 in #questions
Configuring Clerk on the latest release of t3 with tRPC
definitely! also - i don't mean to be rude - just being transparent and voicing the signals from the community that the support on this has been quite far below what you'd usually expect for a p0 (!!!) issue for paying customers
123 replies
TTCTheo's Typesafe Cult
Created by Pavstermeister on 11/5/2023 in #questions
Configuring Clerk on the latest release of t3 with tRPC
these are just the ones i follow
123 replies
TTCTheo's Typesafe Cult
Created by Pavstermeister on 11/5/2023 in #questions
Configuring Clerk on the latest release of t3 with tRPC
No description
123 replies