Skip to content

Commit

Permalink
fix: use named parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
seriousm4x committed Dec 29, 2024
1 parent 9ebe092 commit 47b8155
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions backend/pb/middlewares.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package pb

import (
"fmt"

"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/apis"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/tools/hook"
Expand All @@ -24,8 +23,10 @@ func RequireUpSnapPermission() *hook.Handler[*core.RequestEvent] {
deviceId := e.Request.PathValue("id")

// find record where user has device with power permission
res, err := App.FindFirstRecordByFilter("permissions",
fmt.Sprintf("user.id = '%s' && power.id ?= '%s'", user.Id, deviceId))
res, err := e.App.FindFirstRecordByFilter("permissions", "user.id = {:userId} && power.id ?= {:deviceId}", dbx.Params{
"userId": user.Id,
"deviceId": deviceId,
})
if res == nil || err != nil {
return apis.NewForbiddenError("You are not allowed to perform this request.", nil)
}
Expand Down

0 comments on commit 47b8155

Please sign in to comment.