Skip to content

[Question] Does Prisma middleware work with Postgres RLS? #2

@xinluleo

Description

@xinluleo

In the prisma client extension example https://github.com/prisma/prisma-client-extensions/tree/main/examples/row-level-security, there's a caveat section saying

NOTE: Because this example extension wraps every query in a new batch transaction, explicitly running transactions with companyPrisma.$transaction() may not work as intended. In a future version of Prisma Client, query extensions will have access to information about whether they are run inside a transaction, similar to the runInTransaction parameter provided to Prisma middleware. When this is available, this example will be updated to work for queries run inside explicit transactions.

Does it mean if I use middleware rather than client extension, then postgres RLS can be supported perfectly by passing a runInTransaction: true parameter, with no change to the rest of the readme instructions? Do you mind providing example code of such a middleware? I also read through the thread prisma/prisma#12735, but didn't get a conclusion to this question. Much appreciated for any help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions