diff --git a/core/agents/lastfm/auth_router.go b/core/agents/lastfm/auth_router.go
index ebcf7bcb7..290caaad3 100644
--- a/core/agents/lastfm/auth_router.go
+++ b/core/agents/lastfm/auth_router.go
@@ -65,7 +65,9 @@ func (s *Router) routes() http.Handler {
}
func (s *Router) getLinkStatus(w http.ResponseWriter, r *http.Request) {
- resp := map[string]interface{}{}
+ resp := map[string]interface{}{
+ "apiKey": s.apiKey,
+ }
u, _ := request.UserFrom(r.Context())
key, err := s.sessionKeys.Get(r.Context(), u.ID)
if err != nil && !errors.Is(err, model.ErrNotFound) {
diff --git a/resources/i18n/pt.json b/resources/i18n/pt.json
index 6156eff96..858f750ee 100644
--- a/resources/i18n/pt.json
+++ b/resources/i18n/pt.json
@@ -389,6 +389,7 @@
"language": "Língua",
"defaultView": "Tela inicial",
"desktop_notifications": "Notificações",
+ "lastfmNotConfigured": "A API-Key do Last.fm não está configurada",
"lastfmScrobbling": "Enviar scrobbles para Last.fm",
"listenBrainzScrobbling": "Enviar scrobbles para ListenBrainz",
"replaygain": "Modo ReplayGain",
diff --git a/server/auth.go b/server/auth.go
index dabc452f7..201714ed7 100644
--- a/server/auth.go
+++ b/server/auth.go
@@ -78,9 +78,6 @@ func buildAuthPayload(user *model.User) map[string]interface{} {
if conf.Server.EnableGravatar && user.Email != "" {
payload["avatar"] = gravatar.Url(user.Email, 50)
}
- if conf.Server.LastFM.Enabled {
- payload["lastFMApiKey"] = conf.Server.LastFM.ApiKey
- }
bytes := make([]byte, 3)
_, err := rand.Read(bytes)
diff --git a/ui/src/authProvider.js b/ui/src/authProvider.js
index 92dc4f8ec..588523813 100644
--- a/ui/src/authProvider.js
+++ b/ui/src/authProvider.js
@@ -22,7 +22,6 @@ function storeAuthenticationInfo(authInfo) {
localStorage.setItem('role', authInfo.isAdmin ? 'admin' : 'regular')
localStorage.setItem('subsonic-salt', authInfo.subsonicSalt)
localStorage.setItem('subsonic-token', authInfo.subsonicToken)
- localStorage.setItem('lastfm-apikey', authInfo.lastFMApiKey)
localStorage.setItem('is-authenticated', 'true')
}
@@ -104,7 +103,6 @@ const removeItems = () => {
localStorage.removeItem('role')
localStorage.removeItem('subsonic-salt')
localStorage.removeItem('subsonic-token')
- localStorage.removeItem('lastfm-apikey')
localStorage.removeItem('is-authenticated')
}
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index ebe580bad..178977c7c 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -391,6 +391,7 @@
"language": "Language",
"defaultView": "Default View",
"desktop_notifications": "Desktop Notifications",
+ "lastfmNotConfigured": "Last.fm API-Key is not configured",
"lastfmScrobbling": "Scrobble to Last.fm",
"listenBrainzScrobbling": "Scrobble to ListenBrainz",
"replaygain": "ReplayGain Mode",
diff --git a/ui/src/personal/LastfmScrobbleToggle.jsx b/ui/src/personal/LastfmScrobbleToggle.jsx
index c6499b630..a3c6793ea 100644
--- a/ui/src/personal/LastfmScrobbleToggle.jsx
+++ b/ui/src/personal/LastfmScrobbleToggle.jsx
@@ -5,13 +5,14 @@ import {
FormControlLabel,
LinearProgress,
Switch,
+ Tooltip,
} from '@material-ui/core'
import { useInterval } from '../common'
import { baseUrl, openInNewTab } from '../utils'
import { httpClient } from '../dataProvider'
const Progress = (props) => {
- const { setLinked, setCheckingLink } = props
+ const { setLinked, setCheckingLink, apiKey } = props
const notify = useNotify()
let linkCheckDelay = 2000
let linkChecks = 30
@@ -23,11 +24,9 @@ const Progress = (props) => {
)
const callbackUrl = `${window.location.origin}${callbackEndpoint}`
openedTab.current = openInNewTab(
- `https://www.last.fm/api/auth/?api_key=${localStorage.getItem(
- 'lastfm-apikey',
- )}&cb=${callbackUrl}`,
+ `https://www.last.fm/api/auth/?api_key=${apiKey}&cb=${callbackUrl}`,
)
- }, [])
+ }, [apiKey])
const endChecking = (success) => {
linkCheckDelay = null
@@ -75,6 +74,18 @@ export const LastfmScrobbleToggle = (props) => {
const translate = useTranslate()
const [linked, setLinked] = useState(null)
const [checkingLink, setCheckingLink] = useState(false)
+ const [apiKey, setApiKey] = useState(false)
+
+ useEffect(() => {
+ httpClient('/api/lastfm/link')
+ .then((response) => {
+ setLinked(response.json.status === true)
+ setApiKey(response.json.apiKey)
+ })
+ .catch(() => {
+ setLinked(false)
+ })
+ }, [setLinked, setApiKey])
const toggleScrobble = () => {
if (!linked) {
@@ -89,34 +100,40 @@ export const LastfmScrobbleToggle = (props) => {
}
}
- useEffect(() => {
- httpClient('/api/lastfm/link')
- .then((response) => {
- setLinked(response.json.status === true)
- })
- .catch(() => {
- setLinked(false)
- })
- }, [])
-
return (
-
+ }
+ label={
+ {translate('menu.personal.options.lastfmScrobbling')}
+ }
+ />
+ ) : (
+
+ }
+ label={
+ {translate('menu.personal.options.lastfmScrobbling')}
+ }
/>
- }
- label={
- {translate('menu.personal.options.lastfmScrobbling')}
- }
- />
+
+ )}
{checkingLink && (
-
+
)}
)
diff --git a/ui/src/personal/Personal.jsx b/ui/src/personal/Personal.jsx
index 0b571c0f0..84f9b63e6 100644
--- a/ui/src/personal/Personal.jsx
+++ b/ui/src/personal/Personal.jsx
@@ -27,9 +27,7 @@ const Personal = () => {
{config.enableReplayGain && }
- {config.lastFMEnabled && localStorage.getItem('lastfm-apikey') && (
-
- )}
+ {config.lastFMEnabled && }
{config.listenBrainzEnabled && }