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