noynek2242
noynek2242
Explore posts from servers
PPrisma
Created by noynek2242 on 9/11/2024 in #help-and-questions
Row Level Security Example
I think I got this working, but I've got low confidence. The idea is to pass the session, if I've got it, when I import the DB. ```export async function db(user?: { user?: { id?: string } }) { const userId = user?.user?.id; if (!userId) return _db; const currentUser = await _db.user.findUnique({ where: { id: userId, }, }); console.log({ currentUser }); return currentUser?.companyid ? _db.$extends(forCompany(currentUser.companyid)) : _db; }
2 replies
PPrisma
Created by noynek2242 on 8/15/2024 in #help-and-questions
Multi-tenant approaches
Thanks. Looks like this takes the approach of having separate DBs for each tenant. I think for my purposes a single DB is preferable. I'm hoping to get RLS in Postgres working. Part of the trick was simply to create a new DB user that doesn't have full access. That took me too long to figure out 🙂
4 replies
TTCTheo's Typesafe Cult
Created by noynek2242 on 3/8/2024 in #questions
Decimal Warning
ugh. The JSON stringify is breaking date objects so I've just moved the problem.
3 replies
TTCTheo's Typesafe Cult
Created by noynek2242 on 3/8/2024 in #questions
Decimal Warning
I was able to make the error go away by JSON.parse(JSON.stringify(myDataWithDecimals)) when passing from the server to client component. Feels like a hack though.
3 replies
TTCTheo's Typesafe Cult
Created by noynek2242 on 2/24/2024 in #questions
Sharing Logic Across TRPC Procedures
Thanks. Turns out I was basically doing what it says to do in that server-side-calls section. The part I was missing was finding the right types from Prisma so I could pass around the DB items. The trick there was to import
import { type Prisma } from "@prisma/client";
import { type Prisma } from "@prisma/client";
and then explore those definitions until I found one that made sense. Thanks
3 replies
TTCTheo's Typesafe Cult
Created by noynek2242 on 2/21/2024 in #questions
Client/Server Mutations
Ok, spent a few hours on this and here's what I ended up with: The way T3 is setup using the Next.js App Router, it seems like my api router is already using server actions, but maybe I'm misunderstanding. OnSave, I'm able to call the api router with mutation.mutateAsync(values); My Next challenge was how do I take those returned values and repopulate the form? The issue being if there are any differences between what was saved vs the state of the form. This one took me a while because I'm using uncontrolled form field. What seems to work is to use the React Hook Forms reset method to replace the default values. Anyway, I don't know if there's a better way, but it seems to be working.
7 replies
TTCTheo's Typesafe Cult
Created by noynek2242 on 2/21/2024 in #questions
Client/Server Mutations
Great, thanks for the direction. Definitely wrapping my head around the server-oriented direction still and trying to understand the patterns. Thanks
7 replies