much 2 yearn
much 2 yearn
Explore posts from servers
DTDrizzle Team
Created by much 2 yearn on 9/25/2024 in #help
Where clause on 'with' in findMany
export const getOrgsByMembershipList = cache(async () => {
const user = await getAuthUser();

if (!user) {
throw new Error("User not found");
}

const result = await db.query.membership.findMany({
where: eq(membership.profileId, user.id),
with: {
org: {
columns: {
id: true,
name: true,
},
where: eq(org.defaultOrg, false),
},
},
});

return result;
});
export const getOrgsByMembershipList = cache(async () => {
const user = await getAuthUser();

if (!user) {
throw new Error("User not found");
}

const result = await db.query.membership.findMany({
where: eq(membership.profileId, user.id),
with: {
org: {
columns: {
id: true,
name: true,
},
where: eq(org.defaultOrg, false),
},
},
});

return result;
});
7 replies
CCConvex Community
Created by much 2 yearn on 3/17/2024 in #support-community
Best practice to get userId from from user user in function
in the next/expo monorepo they use getting the userId from the userIdentity, but unsure if this is best practice in case this value will change among auth providers and also because it default to type string and not
Id<"users">
Id<"users">
. Is there a way to get userId from the auth flow for your functions or is the best way to pass the userId as an argument from the frontend?
export const getUserId = async (ctx: { auth: Auth }) => {
return (await ctx.auth.getUserIdentity())?.subject;
};

// Get all notes for a specific user
export const getNotes = query({
args: {},
handler: async (ctx) => {
const userId = await getUserId(ctx);
if (!userId) return null;

const notes = await ctx.db
.query('notes')
.filter((q) => q.eq(q.field('userId'), userId))
.collect();

return notes;
},
});
export const getUserId = async (ctx: { auth: Auth }) => {
return (await ctx.auth.getUserIdentity())?.subject;
};

// Get all notes for a specific user
export const getNotes = query({
args: {},
handler: async (ctx) => {
const userId = await getUserId(ctx);
if (!userId) return null;

const notes = await ctx.db
.query('notes')
.filter((q) => q.eq(q.field('userId'), userId))
.collect();

return notes;
},
});
vs
export const getNotes = query({
args: {
userId: Id<"users">
},
handler: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();
if (identity === null) {
throw new Error("Unauthenticated call to mutation");
}

const notes = await ctx.db
.query('notes')
.filter((q) => q.eq(q.field('userId'), args.userId))
.collect();

return notes;
},
});
export const getNotes = query({
args: {
userId: Id<"users">
},
handler: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();
if (identity === null) {
throw new Error("Unauthenticated call to mutation");
}

const notes = await ctx.db
.query('notes')
.filter((q) => q.eq(q.field('userId'), args.userId))
.collect();

return notes;
},
});
6 replies
CCConvex Community
Created by much 2 yearn on 3/16/2024 in #support-community
Use zod schemas for argument validation
I am using the zod helper library to use zod as validation but it I get an error when trying to use the zod schema from another file, but it works when writing the schema in the zMutation
export const createTemplate = zMutation({
args: createTemplateSchema, //<-breaks
// {
// authorId: zid("users"),
// title: z.string(),
// goal: z.union([
// z.literal("bodybuilding"),
// z.literal("powerlifting"),
// z.literal("powerbuilding"),
// z.literal("mobility"),
// z.literal("sport"),
// z.literal("general"),
// ]),
// format: z.union([z.literal("split"), z.literal("program")]),
// weekLength: z.number(),
// days: z.array(DaySchema),
// maxWeeks: z.number(),
// }
export const createTemplate = zMutation({
args: createTemplateSchema, //<-breaks
// {
// authorId: zid("users"),
// title: z.string(),
// goal: z.union([
// z.literal("bodybuilding"),
// z.literal("powerlifting"),
// z.literal("powerbuilding"),
// z.literal("mobility"),
// z.literal("sport"),
// z.literal("general"),
// ]),
// format: z.union([z.literal("split"), z.literal("program")]),
// weekLength: z.number(),
// days: z.array(DaySchema),
// maxWeeks: z.number(),
// }
error: Index signature for type 'string' is missing in type 'ZodObject. Is it possible to pass a defined schema or must all zod validation be done at that scope
8 replies
CCConvex Community
Created by much 2 yearn on 1/28/2024 in #support-community
useQuery caching and layout question
Hello! Right now I have multiple nested layout pages in next 14 fetching data using useQuery . Is there caching for same queries or will it call each time on the client when using useQuery ? Cuz I call it 4 times in separate layouts. Seems like a bad practice at a glance but it it’s helpful not having to prop drill down. Any advice on best practice here ?
2 replies
TTCTheo's Typesafe Cult
Created by much 2 yearn on 10/14/2023 in #questions
React Native Expo: Take photo with camera and send email with attachment
My current implementation does not work 100% of the time. I am using expo image manipulator and expo print for photos and transforming them. Any advice or direction would be appreciated
3 replies
TTCTheo's Typesafe Cult
Created by much 2 yearn on 8/18/2023 in #questions
T3 real-time / offline
I have a t3 app i made a PWA. I would like to integrate some offline first functionality but there are very few resources regarding this matter that are not - rudimentary dives into indexdb with no sync with your db - graphql solutions (aws amplify / data store , rxdb, couchdb ) Is there a way to support offline first with good database synchronization with t3 stack code base ? I enjoy the stack and would prefer to keep it vs going to a gql alternative
4 replies
TTCTheo's Typesafe Cult
Created by much 2 yearn on 8/8/2023 in #questions
tRPC in nextjs Capacitor app
is it possible to have tRPC in app like this? Capacitor uses an exported static next app so it wont have access to server req/res for trpc contexts. But is it possible to use it for just a wrapper with react-query? I don't believe you can use next auth in an app like this for similar reasons, but I think its possible to use trpc
3 replies
TTCTheo's Typesafe Cult
Created by much 2 yearn on 12/22/2022 in #questions
trpc + Auth0 + turborepo
Hello! I want to build a sass web and mobile application that follows the create-t3-turbo repo. Expo does not support nextAuth so I was wondering what are the implications when using two different auth tools for the apps? I was thinking using auth0. I am using prisma / trpc and most of the examples out there are integrated with just nexAuth. Second question, does anyone have a good repo that uses these tools? Mainly configuring the auth0 middleware with trpc?
4 replies
TTCTheo's Typesafe Cult
Created by much 2 yearn on 9/17/2022 in #questions
Prisma 1-n relation create question
1 replies