Skip to content

Commit acd4369

Browse files
authored
fix: add review auth checks (#315)
1 parent 6ef6a24 commit acd4369

File tree

1 file changed

+15
-5
lines changed
  • starters/nextjs/shopify-ecommerce/dataconnect/connector

1 file changed

+15
-5
lines changed

starters/nextjs/shopify-ecommerce/dataconnect/connector/mutations.gql

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mutation CreateProduct(
55
$name: String!
66
$description: String!
77
$price: Float!
8-
) {
8+
) @auth(level: NO_ACCESS) {
99
product_insert(
1010
data: {
1111
productID: $productID
@@ -27,7 +27,7 @@ mutation UpdateProduct(
2727
$price: Float!
2828
$productID: String!
2929
$productSlug: String!
30-
) {
30+
) @auth(level: NO_ACCESS) {
3131
product_update(
3232
key: { id: $id }
3333
data: {
@@ -43,7 +43,7 @@ mutation UpdateProduct(
4343
}
4444

4545
# Delete a product
46-
mutation DeleteProduct($id: UUID!) {
46+
mutation DeleteProduct($id: UUID!) @auth(level: NO_ACCESS) {
4747
product_delete(key: { id: $id })
4848
}
4949

@@ -56,13 +56,13 @@ mutation CreateReview(
5656
$userName: String!
5757
$rating: Float!
5858
$content: String!
59-
) @auth(level: PUBLIC) {
59+
) @auth(level: USER) {
6060
review_insert(
6161
data: {
6262
productID: $productID
6363
productSlug: $productSlug
6464
productName: $productName
65-
userID: $userID
65+
userID_expr: "auth.uid"
6666
userName: $userName
6767
rating: $rating
6868
content: $content
@@ -73,6 +73,11 @@ mutation CreateReview(
7373

7474
# Update an existing review
7575
mutation UpdateReview($id: UUID!, $rating: Float!, $content: String!) @auth(level: USER) {
76+
query {
77+
review(id: $id) @redact {
78+
userID @check(expr: "this == auth.uid", message: "You can only update your own reviews")
79+
}
80+
}
7681
review_update(
7782
key: { id: $id }
7883
data: {
@@ -85,5 +90,10 @@ mutation UpdateReview($id: UUID!, $rating: Float!, $content: String!) @auth(leve
8590

8691
# Delete a review
8792
mutation DeleteReview($id: UUID!) @auth(level: USER) {
93+
query {
94+
review(id: $id) @redact {
95+
userID @check(expr: "this == auth.uid", message: "You can only update your own reviews")
96+
}
97+
}
8898
review_delete(key: { id: $id })
8999
}

0 commit comments

Comments
 (0)