Spotify unauthenticated: throttled log + admin reconnect on Listening widget
Deploy with Docker Compose / deploy (push) Successful in 40s
Deploy with Docker Compose / deploy (push) Successful in 40s
- Backend logs a rate-limited (1/h) "not authenticated" line when a resolver finds the Spotify client nil instead of silently degrading to null. - New public-but-gated spotifyNeedsReauth query: false for everyone except an admin session whose backend has no client. - The /stp Listening widget offers admins a "Reconnect Spotify" button that hits /api/spotify/auth and navigates to the returned authorisation URL; non-admins still see the widget degrade as before. Co-Authored-By: Claude Code <[email protected]>
This commit is contained in:
@@ -16,6 +16,7 @@ func (r *queryResolver) SpotifyListening(ctx context.Context) (*model.SpotifyPla
|
||||
// A nil client means the OAuth flow has never been completed. Report that
|
||||
// as null rather than an error so the home page renders without it.
|
||||
if r.Store.SpotifyClient == nil {
|
||||
r.Store.LogSpotifyUnauthenticated("spotifyListening")
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -35,6 +36,7 @@ func (r *queryResolver) SpotifyListening(ctx context.Context) (*model.SpotifyPla
|
||||
// SpotifyRecent is the resolver for the spotifyRecent field.
|
||||
func (r *queryResolver) SpotifyRecent(ctx context.Context) ([]*model.SpotifyRecentItem, error) {
|
||||
if r.Store.SpotifyClient == nil {
|
||||
r.Store.LogSpotifyUnauthenticated("spotifyRecent")
|
||||
return []*model.SpotifyRecentItem{}, nil
|
||||
}
|
||||
|
||||
@@ -47,3 +49,22 @@ func (r *queryResolver) SpotifyRecent(ctx context.Context) ([]*model.SpotifyRece
|
||||
|
||||
return mapRecentItems(played), nil
|
||||
}
|
||||
|
||||
// SpotifyNeedsReauth is the resolver for the spotifyNeedsReauth field.
|
||||
//
|
||||
// Admin-gated: false for everyone else, so this query leaks nothing. Admin is
|
||||
// read from the access-token claims the AuthContextMiddleware resolved, not
|
||||
// the database — the same trade-off AdminMiddleware makes (revocation waits
|
||||
// for token expiry).
|
||||
func (r *queryResolver) SpotifyNeedsReauth(ctx context.Context) (bool, error) {
|
||||
if r.Store.SpotifyClient != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if !IsAdminFromCtx(ctx) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
r.Store.LogSpotifyUnauthenticated("spotifyNeedsReauth")
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user