summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-30 11:52:04 -0600
committermo khan <mo@mokhan.ca>2025-07-30 11:52:04 -0600
commit2c4c6cb7fe868229ba3c3a5eddc80d5581574b19 (patch)
tree718332b0c3fe474f6eb2e60f4355e6be3a8bc144
parentc1698f896ff343b1b65e57d3961a78d3bb263b7c (diff)
fix: return a global id for an anonymous user
-rw-r--r--app/db/authorization.go9
-rw-r--r--app/domain/user.go4
2 files changed, 4 insertions, 9 deletions
diff --git a/app/db/authorization.go b/app/db/authorization.go
index 3041f51..ec8e47b 100644
--- a/app/db/authorization.go
+++ b/app/db/authorization.go
@@ -108,14 +108,5 @@ func (r *authorization[T]) Save(ctx context.Context, item T) error {
func (r *authorization[T]) subjectFrom(ctx context.Context) *v1.SubjectReference {
currentUser := cfg.CurrentUser.From(ctx)
- if currentUser == nil {
- return &v1.SubjectReference{
- Object: &v1.ObjectReference{
- ObjectType: "user",
- ObjectId: "*",
- },
- }
- }
-
return currentUser.ToSubjectReference()
}
diff --git a/app/domain/user.go b/app/domain/user.go
index 198fafc..97bacdd 100644
--- a/app/domain/user.go
+++ b/app/domain/user.go
@@ -2,6 +2,7 @@ package domain
import (
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
+ "github.com/xlgmokha/x/pkg/x"
)
type User struct {
@@ -33,6 +34,9 @@ func (self *User) Sparkle(sparklee string, reason string) *Sparkle {
}
func (self *User) ToGID() GlobalID {
+ if x.IsZero(self.Username) {
+ return GlobalID("gid://sparkle/User/*")
+ }
return GlobalID("gid://sparkle/User/" + self.Username)
}