harvey.birdman
harvey.birdman
TTCTheo's Typesafe Cult
Created by Mocha on 6/15/2023 in #questions
tRPC + Clerk: user & org info
Ahh cool cool so something like this would work but probably want to think about how users with multiple orgs would work.
type OrganizationsType = {
[key: string]: string;
};

export const createTRPCContext = (opts: CreateNextContextOptions) => {
const session = getAuth(opts.req);
const { userId, orgId, sessionClaims } = session;

const organizations =
(sessionClaims?.organizations as OrganizationsType) || [];
const organizationKeys = Object.keys(organizations);
console.log("orgnaizationKeys", organizationKeys);

return {
prisma,
currentUser: userId,
currentOrg: orgId ?? organizationKeys[0],
};
};
type OrganizationsType = {
[key: string]: string;
};

export const createTRPCContext = (opts: CreateNextContextOptions) => {
const session = getAuth(opts.req);
const { userId, orgId, sessionClaims } = session;

const organizations =
(sessionClaims?.organizations as OrganizationsType) || [];
const organizationKeys = Object.keys(organizations);
console.log("orgnaizationKeys", organizationKeys);

return {
prisma,
currentUser: userId,
currentOrg: orgId ?? organizationKeys[0],
};
};
43 replies
TTCTheo's Typesafe Cult
Created by Mocha on 6/15/2023 in #questions
tRPC + Clerk: user & org info
Though what you initially did looks like what's recommended by Clerk from today even. https://discord.com/channels/856971667393609759/1118957594816565258/1118962394937438228
43 replies
TTCTheo's Typesafe Cult
Created by Mocha on 6/15/2023 in #questions
tRPC + Clerk: user & org info
Right, on initial sign-up if there's no org I send them to here, and protect the dashboard by checking for org there too and send them back to make it if they haven't already. Never hit your issue since I guess if you do it this way they're always apart of the org workspace and not a personal one.
import { CreateOrganization } from "@clerk/nextjs";

export default function CreateOrganizationPage() {
return (
<div className="flex h-screen items-center justify-center">
<CreateOrganization afterCreateOrganizationUrl="/dashboard" />;
</div>
);
}
import { CreateOrganization } from "@clerk/nextjs";

export default function CreateOrganizationPage() {
return (
<div className="flex h-screen items-center justify-center">
<CreateOrganization afterCreateOrganizationUrl="/dashboard" />;
</div>
);
}
43 replies
TTCTheo's Typesafe Cult
Created by Mocha on 6/15/2023 in #questions
tRPC + Clerk: user & org info
Ok yeah, if I add the org switcher component and switch to personal workspace I start getting the same errors.
❌ tRPC failed on appPermissions.getByUserId: No org
orgId undefined
orgSlug undefined
❌ tRPC failed on appPermissions.getByUserId: No org
orgId undefined
orgSlug undefined
43 replies
TTCTheo's Typesafe Cult
Created by Mocha on 6/15/2023 in #questions
tRPC + Clerk: user & org info
I'll play around with it and see if I can reproduce
43 replies
TTCTheo's Typesafe Cult
Created by Mocha on 6/15/2023 in #questions
tRPC + Clerk: user & org info
Hmm I don't have anything set in this app that allows users to switch organizations and I require an org to get to the dashboard. So on initial sign-up I check if there's an org and if not make them create one. But don't have anything that allows them to switch to a personal workspace or change/create orgs
43 replies
TTCTheo's Typesafe Cult
Created by harvey.birdman on 6/15/2023 in #questions
Resend Icon Animations what are they?
Definitely something just like it. Just started clicking around and thinking I must change all my icons now ha.
3 replies
TTCTheo's Typesafe Cult
Created by Mocha on 6/15/2023 in #questions
tRPC + Clerk: user & org info
Here's my full trpc.ts just so you see how it's working for me https://gist.github.com/msywulak/4f5c0f6991dfbcef46d801f316f4f46e
43 replies
TTCTheo's Typesafe Cult
Created by Mocha on 6/15/2023 in #questions
tRPC + Clerk: user & org info
Definitely a bit odd if it all looks like it should work. Might be worth asking in the Clerk discord if everything looks good otherwise. Have multiple clerk applications and connecting to the wrong one? Sorry not too much help just saw something i recognized
43 replies
TTCTheo's Typesafe Cult
Created by Mocha on 6/15/2023 in #questions
tRPC + Clerk: user & org info
Is the user you're logging in with a part of an org and has a slug defined?
export const createTRPCContext = (opts: CreateNextContextOptions) => {
const session = getAuth(opts.req);
const { userId, orgId, orgSlug } = session;
// const sesh = getAuth(req);

console.log("userId", userId);
console.log("orgId", orgId);
console.log("orgSlug", orgSlug);

return {
prisma,
currentUser: userId,
currentOrg: orgId,
};
};

userId user_2NnQUPMwpBPKHbkZM2c7AkhwXnD
orgId org_2OAA34B7ZEoNL2YitGGTmPS86m6
orgSlug polvo
export const createTRPCContext = (opts: CreateNextContextOptions) => {
const session = getAuth(opts.req);
const { userId, orgId, orgSlug } = session;
// const sesh = getAuth(req);

console.log("userId", userId);
console.log("orgId", orgId);
console.log("orgSlug", orgSlug);

return {
prisma,
currentUser: userId,
currentOrg: orgId,
};
};

userId user_2NnQUPMwpBPKHbkZM2c7AkhwXnD
orgId org_2OAA34B7ZEoNL2YitGGTmPS86m6
orgSlug polvo
43 replies
TTCTheo's Typesafe Cult
Created by Mocha on 6/15/2023 in #questions
tRPC + Clerk: user & org info
import { prisma } from "~/server/db";

/**
* 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 = (opts: CreateNextContextOptions) => {
const { req } = opts;
const sesh = getAuth(req);

const userId = sesh.userId;
const orgId = sesh.orgId;

return {
prisma,
currentUser: userId,
currentOrg: orgId,
};
};
import { prisma } from "~/server/db";

/**
* 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 = (opts: CreateNextContextOptions) => {
const { req } = opts;
const sesh = getAuth(req);

const userId = sesh.userId;
const orgId = sesh.orgId;

return {
prisma,
currentUser: userId,
currentOrg: orgId,
};
};
Works for me
43 replies