From 3afc1a553f1dbf603bc55442d85f2df31d847c50 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 23 Oct 2025 10:10:00 +0200 Subject: [PATCH] auth/middleware: return semantic errors on auth failure This time with a much simpler approach than the last one that caused some authentication issues for chat.sr.ht. --- auth/middleware.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/auth/middleware.go b/auth/middleware.go index 74d44aa48d0d914e9d78bff0429f659caf803675..24fd0cc6869b4fa3f380b08e496fa0e0c76852e9 100644 --- a/auth/middleware.go +++ b/auth/middleware.go @@ -101,11 +101,12 @@ func (authctx *AuthContext) Access(scope, kind string) error { } func authError(w http.ResponseWriter, reason string, code int) { - gqlerr := gqlerror.Errorf("Authentication error: %s", reason) b, err := json.Marshal(struct { Errors []*gqlerror.Error `json:"errors"` }{ - Errors: []*gqlerror.Error{gqlerr}, + Errors: []*gqlerror.Error{ + errors.New(errors.Unauthorized, reason), + }, }) if err != nil { panic(err)