From 220bbc3d2df9e3dfc57ee0ba69218acf35d6e86a Mon Sep 17 00:00:00 2001 From: advplyr Date: Fri, 29 Apr 2022 17:43:46 -0500 Subject: [PATCH] Fix:Series covers on home page not spread out correctly #505, Update:Server settings are now returned with auth requests --- client/components/covers/GroupCover.vue | 8 ++++++++ client/layouts/default.vue | 6 ------ client/pages/login.vue | 15 +++++++++++---- server/Auth.js | 15 ++++++++++----- server/Server.js | 1 + server/controllers/MiscController.js | 7 ++++++- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/client/components/covers/GroupCover.vue b/client/components/covers/GroupCover.vue index 8af50fd0..015e539f 100644 --- a/client/components/covers/GroupCover.vue +++ b/client/components/covers/GroupCover.vue @@ -44,6 +44,14 @@ export default { this.$nextTick(this.init) } } + }, + width: { + handler(newVal) { + if (newVal) { + this.isInit = false + this.$nextTick(this.init) + } + } } }, computed: { diff --git a/client/layouts/default.vue b/client/layouts/default.vue index 96f16840..2f14f426 100644 --- a/client/layouts/default.vue +++ b/client/layouts/default.vue @@ -106,12 +106,6 @@ export default { } } if (payload.serverSettings) { - this.$store.commit('setServerSettings', payload.serverSettings) - - if (payload.serverSettings.chromecastEnabled) { - console.log('Chromecast enabled import script') - require('@/plugins/chromecast.js').default(this) - } } // Start scans currently running diff --git a/client/pages/login.vue b/client/pages/login.vue index 7d5094e4..af3dfa17 100644 --- a/client/pages/login.vue +++ b/client/pages/login.vue @@ -48,8 +48,15 @@ export default { } }, methods: { - setUser(user, defaultLibraryId) { - this.$store.commit('libraries/setCurrentLibrary', defaultLibraryId) + setUser({ user, userDefaultLibraryId, serverSettings }) { + this.$store.commit('setServerSettings', serverSettings) + + if (serverSettings.chromecastEnabled) { + console.log('Chromecast enabled import script') + require('@/plugins/chromecast.js').default(this) + } + + this.$store.commit('libraries/setCurrentLibrary', userDefaultLibraryId) this.$store.commit('user/setUser', user) }, async submitForm() { @@ -69,7 +76,7 @@ export default { if (authRes && authRes.error) { this.error = authRes.error } else if (authRes) { - this.setUser(authRes.user, authRes.userDefaultLibraryId) + this.setUser(authRes) } this.processing = false }, @@ -87,7 +94,7 @@ export default { } }) .then((res) => { - this.setUser(res.user, res.userDefaultLibraryId) + this.setUser(res) this.processing = false }) .catch((error) => { diff --git a/server/Auth.js b/server/Auth.js index 4fd68a16..852f5f2f 100644 --- a/server/Auth.js +++ b/server/Auth.js @@ -100,6 +100,14 @@ class Auth { }) } + getUserLoginResponsePayload(user) { + return { + user: user.toJSONForBrowser(), + userDefaultLibraryId: user.getDefaultLibraryId(this.db.libraries), + serverSettings: this.db.serverSettings.toJSON() + } + } + async login(req, res) { var username = (req.body.username || '').toLowerCase() var password = req.body.password || '' @@ -120,17 +128,14 @@ class Auth { if (password) { return res.status(401).send('Invalid root password (hint: there is none)') } else { - return res.json({ user: user.toJSONForBrowser(), userDefaultLibraryId: user.getDefaultLibraryId(this.db.libraries) }) + return res.json(this.getUserLoginResponsePayload(user)) } } // Check password match var compare = await bcrypt.compare(password, user.pash) if (compare) { - res.json({ - user: user.toJSONForBrowser(), - userDefaultLibraryId: user.getDefaultLibraryId(this.db.libraries) - }) + res.json(this.getUserLoginResponsePayload(user)) } else { Logger.debug(`[Auth] Failed login attempt ${req.rateLimit.current} of ${req.rateLimit.limit}`) if (req.rateLimit.remaining <= 2) { diff --git a/server/Server.js b/server/Server.js index ed680a6f..4692814d 100644 --- a/server/Server.js +++ b/server/Server.js @@ -409,6 +409,7 @@ class Server { await this.db.updateEntity('user', user) const initialPayload = { + // TODO: this is sent with user auth now, update mobile app to use that then remove this serverSettings: this.db.serverSettings.toJSON(), audiobookPath: global.AudiobookPath, metadataPath: global.MetadataPath, diff --git a/server/controllers/MiscController.js b/server/controllers/MiscController.js index a65a7e9c..e85b85c1 100644 --- a/server/controllers/MiscController.js +++ b/server/controllers/MiscController.js @@ -230,7 +230,12 @@ class MiscController { Logger.error('Invalid user in authorize') return res.sendStatus(401) } - res.json({ user: req.user, userDefaultLibraryId: req.user.getDefaultLibraryId(this.db.libraries) }) + const userResponse = { + user: req.user, + userDefaultLibraryId: req.user.getDefaultLibraryId(this.db.libraries), + serverSettings: this.db.serverSettings.toJSON() + } + res.json(userResponse) } getAllTags(req, res) {