From 1c1dc49c6921dea4c13a91e364a9529c8d87c52f Mon Sep 17 00:00:00 2001 From: Valentin Kaelin Date: Tue, 3 Sep 2019 19:56:41 +0200 Subject: [PATCH] Fix: check summoner name server side to prevent Firefox error --- client/src/components/SearchForm.vue | 21 +++++++-------------- client/src/views/Summoner.vue | 5 +++++ server/src/Jax/JaxRequest.js | 2 +- server/src/server.js | 11 ++++++++++- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/client/src/components/SearchForm.vue b/client/src/components/SearchForm.vue index 3590c2e..89a703c 100644 --- a/client/src/components/SearchForm.vue +++ b/client/src/components/SearchForm.vue @@ -7,7 +7,7 @@ type="text" autofocus class="input w-full px-2 py-4 rounded-lg outline-none pl-8 pr-16 font-bold" - > + />
- - + > {{ region }}
@@ -86,15 +85,9 @@ export default { } }, formSubmit() { - const regexNames = new RegExp('^[0-9\\p{L} _\\.]+$', 'u') - - if(regexNames.exec(this.summoner)) { - this.$emit('formSubmit', this.summoner.split(' ').join(''), this.selectedRegion.toLowerCase()) - } else { - this.$store.dispatch('notification/add', { - type: 'error', - message: 'Summoner Name entered is incorrect.' - }) + const search = this.summoner.split(' ').join('') + if (search.length) { + this.$emit('formSubmit', search, this.selectedRegion.toLowerCase()) } } } diff --git a/client/src/views/Summoner.vue b/client/src/views/Summoner.vue index 16f23b9..6ac4251 100644 --- a/client/src/views/Summoner.vue +++ b/client/src/views/Summoner.vue @@ -140,6 +140,11 @@ export default { } else { this.summonerFound = false this.loading = false + + this.$store.dispatch('notification/add', { + type: 'error', + message: 'Summoner not found.' + }) console.log('Summoner not found') } } catch (error) { diff --git a/server/src/Jax/JaxRequest.js b/server/src/Jax/JaxRequest.js index d97fedf..aa1e9c9 100644 --- a/server/src/Jax/JaxRequest.js +++ b/server/src/Jax/JaxRequest.js @@ -16,7 +16,7 @@ class JaxRequest { return JSON.parse(resp) } catch ({ statusCode, ...rest }) { - console.log('error: ' + statusCode, rest) + console.log('error: ' + statusCode) } } diff --git a/server/src/server.js b/server/src/server.js index 848eaa8..a66925f 100644 --- a/server/src/server.js +++ b/server/src/server.js @@ -42,11 +42,21 @@ app.post('/api', async function (req, res) { console.log(req.body.summoner, req.body.region) console.time('all') + /* Check if the summonerName is correct before fetching Riot API */ + const regexSummonerName = new RegExp('^[0-9\\p{L} _\\.]+$', 'u') + if (!regexSummonerName.exec(req.body.summoner)) { + return res.send(null) + } + const finalJSON = {} jax.regionName = req.body.region try { const account = await jax.Summoner.summonerName(req.body.summoner) + + // Check if the summoner is found + if (!account) return res.send(null) + finalJSON.account = account const ranked = await jax.League.summonerID(account.id) @@ -66,7 +76,6 @@ app.post('/api', async function (req, res) { console.timeEnd('all') } catch (error) { console.log('username not found') - console.log(error) res.send(null) } })