Row Level Security Example
I'm playing with this example on client extension and row-level-security (RLS). The thing that's got me confused is the example gets a user just by grabbing the first item
I'm using next-auth and I can't figure out how to get the signed-in user from here. Any suggestions?
https://github.com/prisma/prisma-client-extensions/blob/main/row-level-security/script.ts#L42
GitHub
prisma-client-extensions/row-level-security/script.ts at main · pri...
Examples of Prisma Client extensions. Contribute to prisma/prisma-client-extensions development by creating an account on GitHub.
1 Reply
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;
}