fix: invalid json response when login gate is disabled

This commit is contained in:
Gabe Farrell 2026-01-26 14:44:07 -05:00
parent 42b32c7920
commit 2356e75a3b
2 changed files with 16 additions and 4 deletions

View file

@ -367,6 +367,16 @@ func TestLoginGate(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, 204, resp.StatusCode)
req, err = http.NewRequest("GET", host()+"/apis/web/v1/artist?id=3", nil)
require.NoError(t, err)
resp, err = http.DefaultClient.Do(req)
assert.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode)
var artist models.Artist
err = json.NewDecoder(resp.Body).Decode(&artist)
require.NoError(t, err)
assert.Equal(t, "ネクライトーキー", artist.Name)
cfg.SetLoginGate(true)
req, err = http.NewRequest("GET", host()+"/apis/web/v1/artist?id=3", nil)
@ -382,6 +392,9 @@ func TestLoginGate(t *testing.T) {
resp, err = http.DefaultClient.Do(req)
assert.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode)
err = json.NewDecoder(resp.Body).Decode(&artist)
require.NoError(t, err)
assert.Equal(t, "ネクライトーキー", artist.Name)
cfg.SetLoginGate(false)

View file

@ -62,6 +62,7 @@ func Authenticate(store db.DB, mode AuthMode) func(http.Handler) http.Handler {
}
} else {
next.ServeHTTP(w, r)
return
}
}
@ -76,10 +77,8 @@ func Authenticate(store db.DB, mode AuthMode) func(http.Handler) http.Handler {
return
}
if user != nil {
ctx = context.WithValue(ctx, UserContextKey, user)
r = r.WithContext(ctx)
}
next.ServeHTTP(w, r)
})