-
Notifications
You must be signed in to change notification settings - Fork 30
Support for request.parameters(), request.jwt() and request.user_id()
#31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
They are now more consistent with standard parameter queries. This adds support for request.parameters() in static parameter queries.
This now matches the rest of parameter query handling. This adds support for request.parameters() in select clause of parameter queries.
This adds the raw JWT payload to the request parameters, and moves some normalization logic from the auth function to sync rules.
🦋 Changeset detectedLatest commit: e0200a3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
Good so far. |
Chriztiaan
previously approved these changes
Jul 8, 2024
Chriztiaan
previously approved these changes
Jul 8, 2024
Chriztiaan
previously approved these changes
Jul 9, 2024
Chriztiaan
approved these changes
Jul 9, 2024
request.parameters()request.parameters(), request.jwt() and request.user_id()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds new functions, for use in parameter queries only:
request.jwt(): Returns the entire (signed) JWT payload as a JSON string.request.parameters(): Returns the client parameters (unauthenticated) as a JSON string.request.user_id(): Returns the token subject, same astoken_parameters.user_id().These are similar to the current
token_parametersanduser_parameters(added in #7) respectively. The major differences are that the entire payloads are preserved as-is, which can make usage a little more intuitive. It also includes JWT payload fields not previously accessible.Examples:
Implementation
This builds on the refactor in #30.
The biggest change here is to make static parameter queries behave the same as other parameter queries. Previously, static parameter queries treated
token_parametersanduser_parametersas row data, while other queries treated it as parameter data. Now, both treat it as parameter data.From there it's just implementing two special-case functions as
ParameterValueClauses.SyncParameterswas also refactored to get access to the raw payloads in sync rules.Naming things
request.jwt()to matchrequest.parameters(),or?auth.jwt()to match Supabase RLSrequest.user_id(),or?auth.uid()to match Supabase RLSrequest.unauthenticated_parameters()?Warning on potentially dangerous queries
To identify potentially dangerous queries, this checks for queries that:
request.parameters()(oruser_parameters).request.jwt()(ortoken_parameters).There are some special cases deviating from those, but that's the general principle. These warnings can be disabled by specifying
accept_potentially_dangerous_queries: truein the bucket definition.Message updated since screenshot:
Accepting the warning:

Function documentation
This adds basic documentation for each function definition, for use in the sync rules editor.