Skip to content

Commit 788fdfe

Browse files
committed
feat: propagate kind + access_level as JWT claims in pgSettings
Adds jwt.claims.access_level and jwt.claims.kind to PostgreSQL session settings so PG functions can read them via current_setting(). This lets the DB layer make decisions based on credential type (api_key vs session) and access level (read_write vs read_only) without additional lookups.
1 parent 17dbfc3 commit 788fdfe

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

graphql/server/src/middleware/graphile.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ const buildPreset = (
189189
...context,
190190
};
191191

192+
// Propagate credential metadata as JWT claims so PG functions
193+
// can read them via current_setting('jwt.claims.access_level') etc.
194+
if (req.token.access_level) {
195+
pgSettings['jwt.claims.access_level'] = req.token.access_level;
196+
}
197+
if (req.token.kind) {
198+
pgSettings['jwt.claims.kind'] = req.token.kind;
199+
}
200+
192201
// Enforce read-only transactions for read_only credentials (API keys, etc.)
193202
if (req.token.access_level === 'read_only') {
194203
pgSettings['default_transaction_read_only'] = 'on';

0 commit comments

Comments
 (0)