Spotify unauthenticated: throttled log + admin reconnect on Listening widget
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:
2026-09-22 22:54:48 +01:00
co-authored by Claude Code
parent 241acb82d9
commit ff186f04a7
6 changed files with 163 additions and 19 deletions
+10
View File
@@ -22,6 +22,12 @@ const song_template = {
export const useSongsStore = defineStore("songs", () => {
const songs = ref([song_template]);
// signalEnglish (see below) plus an admin-only "needs Spotify re-auth"
// flag, fetched alongside the songs. The widget uses it to offer the
// reconnect link; non-admins also get the field (false) because the query
// is public and the resolver simply gates it.
const needsReauth = ref(false);
const songsCount = computed(() => songs.value.length);
const homeData = useHomeDataStore();
@@ -52,8 +58,10 @@ export const useSongsStore = defineStore("songs", () => {
}
playedAt
}
spotifyNeedsReauth
}
`);
needsReauth.value = !!data.spotifyNeedsReauth;
if (Array.isArray(data.spotifyRecent) && data.spotifyRecent.length > 0) {
songs.value = data.spotifyRecent;
}
@@ -67,6 +75,8 @@ export const useSongsStore = defineStore("songs", () => {
songsCount,
needsReauth,
fetchSongs,
};
});
+36 -1
View File
@@ -8,6 +8,7 @@
import Header from "@/components/text/Header.vue";
import { computed, onMounted } from "vue";
import { useSongsStore } from "@/stores/songs";
import { useAuthStore } from "@/stores/auth";
import { useRotation } from "@/js/useRotation";
const ROTATE_MS = 5000;
@@ -22,6 +23,30 @@ const { idx, next: nextSong } = useRotation(() => songsStore.songs, ROTATE_MS, {
const song = computed(() => songsStore.songs[idx.value]);
// Admin-only reconnect: when spotifyNeedsReauth comes back true the backend
// has no Spotify client (OAuth never completed or the token was revoked), so
// the widget offers the OAuth start endpoint instead of the template song.
// Non-admins get none of this.
const auth = useAuthStore();
const showReconnect = computed(
() => auth.loggedIn && auth.user.admin && songsStore.needsReauth,
);
// GET /api/spotify/auth returns { url } — the Spotify authorisation URL with
// a one-shot state nonce. Navigating to it runs the OAuth dance; the callback
// installs the client server-side. Errors are swallowed: the widget simply
// stays as it was.
async function reconnect() {
try {
const res = await fetch("/api/spotify/auth");
if (!res.ok) return;
const { url } = await res.json();
window.location.href = url;
} catch (err) {
console.error("Cannot start Spotify re-authentication", err);
}
}
onMounted(() => {
songsStore.fetchSongs();
});
@@ -33,7 +58,17 @@ onMounted(() => {
<Header>Listening To</Header>
</div>
<div class="content-scroll">
<Transition name="fade">
<div v-if="showReconnect" class="flex flex-col items-center">
<p class="text-center">Spotify needs reconnecting.</p>
<button
type="button"
class="underline text-mid cursor-pointer bg-transparent border-0"
@click="reconnect"
>
Reconnect Spotify
</button>
</div>
<Transition name="fade" v-else>
<div
@click="nextSong"
:key="song.track.name"