Is it possible to decode a JWT without switching to the user? #2690
-
I'd like to write a function that creates a new user/role if they do not exist, with default permissions, using data from the JWT. The only way I can see how to do that is to create the user from an anon role, pass the token in the request body (or header but not Authentication header, as that would trigger the role switch), decode the token there, and then create the user if they do not exist. That seems pretty non-trivial and it bypasses all of the built in decoding done in PostgREST. Is there another possible way that I could do this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You could use the same static PostgREST would always change to the Then create a |
Beta Was this translation helpful? Give feedback.
You could use the same static
role: authenticator
in each JWT - and then have a second field in the payload which contains the "real" role.PostgREST would always change to the
authenticator
role first - which it already has anyway. No-op.Then create a
db-pre-request
function, which checks the JWT payload, creates the real role if missing and finally does it's ownSET ROLE <real-role>
.